console.log(undefined ?? 'default');
Why am I getting an error Uncaught SyntaxError: Unexpected token '?'
See Question&Answers more detail:osconsole.log(undefined ?? 'default');
Why am I getting an error Uncaught SyntaxError: Unexpected token '?'
See Question&Answers more detail:osUpdated 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
orundefined
, and otherwise returns its left-hand side operand.
let x = undefined;
console.log(x ?? 'default');
x = null;
console.log(x ?? 'default');