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")


Correct Option: C

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.

Find more quizzes: