LearnFrenzy
Sign in Take a free test

Operators · Predict the Output · Question 6

|| vs ?? with zero Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

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

main.js
const count = 0;
console.log(count || 10, count ?? 10);
  • A 0 0
  • B 10 0 Correct
  • C 10 10
  • D 0 10
Correct Answer: Option B

0 is falsy, so || returns 10. 0 is not null or undefined, so ?? keeps it.

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