LearnFrenzy
Sign in Take a free test

Operators · Predict the Output · Question 20

Which calls actually run? Answer, explanation & discussion

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

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

main.js
let calls = 0;
const inc = () => ++calls;
false && inc();
true || inc();
null ?? inc();
0 ?? inc();
console.log(calls);
  • A 0
  • B 2
  • C 4
  • D 1 Correct
Correct Answer: Option D

The right side runs only when the left side does not decide the result: false && … and true || … skip it, null ?? … runs it, 0 ?? … skips it because 0 is not nullish.

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