+ 4
Nullish coalescing
What is the output of below code : let firstName; let lastName; let nickName = âWolverineâ; console.log(firstName ?? lastName ?? nickName ?? âArshad khanâ);
6 Answers
+ 2
not the same result if the condition returns an empty string '' or 0. It returns the left-hand side instead.
const foo = '' ?? 'default string';
console.log(foo);
// output: ''
const boo = '' || 'default string';
console.log(boo)
// output: 'default string'
const baz = 0 ?? 42;
console.log(baz);
// output: 0
const bar = 0 || 42
console.log(bar)
// output: 42
https://code.sololearn.com/cmGho9jKf8r0/?ref=app
+ 2
Solomoni Railoa But we can achieve the same using || operator.
+ 1
Solomoni Railoa correct
+ 1
Bob_Li goog explanation.