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

  1. "Hello World"

  2. document.write("Hello World")

  3. response.write("Hello World")

  4. ("Hello World")


Correct Option: B

AI Explanation

To answer this question, you need to have a basic understanding of JavaScript syntax for displaying text on a webpage. Let's go through each option to understand why it is correct or incorrect:

Option A) "Hello World" - This option is incorrect because it is just a string literal and does not display the text on a webpage.

Option B) document.write("Hello World") - This option is correct because it uses the document.write() method to display the text "Hello World" on a webpage.

Option C) response.write("Hello World") - This option is incorrect because response.write() is not a valid JavaScript method for displaying text on a webpage.

Option D) ("Hello World") - This option is incorrect because it is missing a statement or method to display the text on a webpage.

The correct answer is B) document.write("Hello World"). This option is correct because it uses the document.write() method to display the text "Hello World" on a webpage.

Find more quizzes: