Question 20
Back to Exercise
What does the following JavaScript code print (console output, as in Node.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!