A

Admin • 802.91K Points
Coach

Q. The script tag must be placed in

  • (A) head
  • (B) head and body
  • (C) title and head
  • (D) all of the mentioned
  • Correct Answer - Option(B)
  • Views: 8
  • Filed under category JavaScript
  • Hashtags:

Explanation by: Admin

In HTML, the <script> tag can be placed in both the <head> and <body> sections:

In the <head> section:

  • If the script is needed before the page loads (e.g., setting up configurations or defining functions).
  • Example:

In the <body> section:

  • Commonly used for scripts that interact with page elements to ensure the document is fully loaded.
  • Example:

In both <head> and <body>:

  • A mix of both can be used depending on the script’s purpose.

Incorrect options:

  • (C) title and head → <script> is not allowed inside <title>.
  • (D) all of the mentioned → Since <script> is not valid inside <title>, this option is incorrect.
<body>
<script>
console.log("Script in body");
</script>
</body>
<head>
<script>
console.log("Script in head");
</script>
</head>

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.