LearnFrenzy
Sign in Take a free test

Operators · Predict the Output · Question 4

null and undefined compared with 0 Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
console.log(null == 0, null >= 0, undefined == 0, undefined >= 0);
  • A false false false false
  • B true true false false
  • C false true false false Correct
  • D false true false true
Correct Answer: Option C

== never converts null/undefined to numbers. Relational operators convert null to 0 (0 >= 0 is true) and undefined to NaN (every comparison with NaN is false).

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links