Multiple choice technology web technology

What is the correct JavaScript syntax to write "Hello World"?

  1. response.write("Hello World")

  2. "Hello World"

  3. document.write("Hello World")

  4. ("Hello World")

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The correct JavaScript syntax to output text is document.write("Hello World"). The document object's write() method outputs text to the HTML document. Response.write() is ASP syntax, and just writing the string or parentheses alone are not valid JavaScript.

AI explanation

To answer this question, you need to understand the correct syntax for outputting text in JavaScript.

Let's go through each option to understand why it is correct or incorrect:

Option A) response.write("Hello World") - This option is incorrect. "response.write" is not a valid JavaScript syntax for outputting text.

Option B) "Hello World" - This option is incorrect. While it is a valid string value, it is not being outputted to the document.

Option C) document.write("Hello World") - This option is correct. The "document.write" function is a valid JavaScript syntax for outputting text to the document.

Option D) ("Hello World") - This option is incorrect. The parentheses are not necessary and do not form a valid syntax for outputting text.

The correct answer is C) document.write("Hello World"). This option is correct because it uses the correct JavaScript syntax to output the text "Hello World" to the document.