console.log(undefined ?? 'default');
Why am I getting an error Uncaught SyntaxError: Unexpected token '?'
Updated answer
The nullish-coalescing operator was added in ECMAScript 11.
The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand.
null
undefined
let x = undefined; console.log(x ?? 'default'); x = null; console.log(x ?? 'default');
2.1m questions
2.1m answers
60 comments
57.0k users