πŸ“Š JavaScript
Q. The script tag must be placed in
  • (A) head
  • (B) head and body
  • (C) title and head
  • (D) all of the mentioned
πŸ’¬ Discuss
βœ… Correct Answer: (B) head and body

Explanation:

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>

Explanation by: Official MCQ Buddy

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>

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
362
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Babita
Publisher
πŸ“ˆ
92%
Success Rate