EasyType Coercion💻 Output Question

Short circuit: || vs ?? difference

💡

Hint

?? only triggers on null/undefined. || also triggers on 0, "", false. Use ?? when 0 or "" are valid values.

What does this output?

console.log(0 || 'default');
console.log(1 && 'value');
console.log(null ?? 'fallback');
console.log(0 ?? 'not this');

Correct Output

default
value
fallback
0

Why this output?

Explanation: ||: first truthy or last. &&: first falsy or last. ??: right only if left is null/undefined. 0 is not null, so ?? keeps 0.

Key Insight: ?? only triggers on null/undefined. || also triggers on 0, "", false. Use ?? when 0 or "" are valid values.

More Type Coercion Output Questions

EasyPlus operator: string concat vs numeric addMediumLoose equality edge cases with nullEasytypeof for common valuesMediumTruthy and falsy — empty array and object are truthy

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz