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');
1.4m articles
1.4m replys
5 comments
57.0k users