What does console.log(null ?? undefined ?? 'last'); output?
A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-145.js
1console.log(null??undefined??'last');
Quirks
Answer & explanation
Console output
last
Why
Chained ?? operators evaluate left to right, returning the first operand that is neither null nor undefined. Since both null and undefined are nullish, the chain skips them and resolves to "last". This makes ?? convenient for selecting the first meaningful default from a series of possibly-absent values.