MediumModern JS💻 Output Question

Nullish coalescing ?? vs OR ||

💡

Hint

?? only triggers on null/undefined. || triggers on any falsy value including 0.

What does this output?

const config = { timeout: 0, debug: null };
console.log(config.timeout  ?? 1000);
console.log(config.timeout  || 1000);
console.log(config.debug    ?? true);

Correct Output

0
1000
true

Why this output?

Explanation: timeout=0: ?? keeps 0 (not null/undefined). || treats 0 as falsy → 1000. debug=null: ?? triggers → true.

Key Insight: ?? only triggers on null/undefined. || triggers on any falsy value including 0.

More Modern JS Output Questions

EasyDestructuring defaults apply only for undefinedEasyObject spread — later properties winMediumOptional chaining prevents TypeError on missing propertiesEasyTemplate literal expressions

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz