Nullish Coalescing

Nullish Coalescing

Nullish Coalescing operator was introduced in ES6 2020.

this operator is used with the double question mark ??

it only works with nullish values, nullish values are (null and undefined) and ignore falsy value like (zero and empty string) 0 and " "

in some cases we would not like to ignore the falsy value, in such cases, Nullish Coalescing operator comes into the picture.

without nullish operator example 1 :

let i = 0;

console.log(i || 10) // result : 10

with nullish operator example 2 :

let i = 0;

console.log(i ?? 10) // result : 0

Sajjad Ali

JavaScript | MERN Stack | ReactJs | NextJs

1y

Good job Muhammad Ahmad

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics