EXAMRADAR

Question: What will be the result of the following code? <pre> <code>var x = 2;</code><code>if (x > 3)</code><code> {console.log("Hello, world!");</code><code> } else if (x < 1) </code><code>{console.log("Goodbye, world!");</code><code>} else {</code><code> console.log("Hi there, world!");</code><code> }</code> </pre>

Answer:

Since neither the first `if` nor the `else if` condition is true, the `else` block will be executed, logging "Hi there, world!"

MCQ: What will be the result of the following code? <pre> <code>var x = 2;</code><code>if (x > 3)</code><code> {console.log("Hello, world!");</code><code> } else if (x < 1) </code><code>{console.log("Goodbye, world!");</code><code>} else {</code><code> console.log("Hi there, world!");</code><code> }</code> </pre>

Correct Answer: A. "Hello, world!" will be logged

Explanation:

Since neither the first `if` nor the `else if` condition is true, the `else` block will be executed, logging "Hi there, world!"

Discuss a Question

Related Questions

You may be interested in:

Web Fundamental MCQs

Recently Added Articles

How Can AI Simplify the Academic Life of Students?

How Can AI Simplify the Academic Life of Students?

Last updated on: April 16, 2025Posted by: ExamRadar

Want to Clear IBPS RRB PO? Master These Mock Test Hacks!

Last updated on: March 10, 2025Posted by: ExamRadar

Top AI Tools for Instantly Detecting Plagiarized Writing

Last updated on: December 5, 2024Posted by: ExamRadar

5 Important Tools for System Administrators

Last updated on: December 1, 2024Posted by: ExamRadar

Image to Text Conversion Made Easy: Online Tool Insights

Last updated on: April 12, 2024Posted by: ExamRadar

Tips to Write an Email: Pro Email Writing Tips

Last updated on: March 20, 2024Posted by: ExamRadar

Yellow diamond: the market worth and value

Last updated on: March 9, 2024Posted by: ExamRadar