Which tag is used to enclose any number of javascript statements in HTML…
2019
Which tag is used to enclose any number of javascript statements in HTML document?
- A.
<code>
- B.
<script>
- C.
<title>
- D.
<body>
Attempted by 240 students.
Show answer & explanation
Correct answer: B
Answer: Use the <script> tag to enclose JavaScript statements.
The <script> tag can contain any number of JavaScript statements and must be closed with </script>.
It can be placed in either the head or the body of the HTML document.
Use the src attribute to include external JavaScript files (for example: src="app.js").
Example: <script>console.log('Hello World');</script>
Why the other tags are incorrect:
<code> is for marking code snippets for display and does not execute JavaScript.
<title> sets the document title shown in the browser tab and cannot contain executable JavaScript.
<body> defines the visible content area of the page; scripts may be placed inside it using <script>, but <body> itself does not enclose executable JavaScript.
A video solution is available for this question — log in and enroll to watch it.