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

MERN Stack | ReactJs/NextJs/Gatsby/Sveltkit | Software Engineer

2 年

Good job Muhammad Ahmad

要查看或添加评论,请登录

Muhammad Ahmad的更多文章

  • Add method to array globally

    Add method to array globally

    Add method to array is very straight forward but we need first to clear the core concepts to get it done. we must know…

  • IIFE

    IIFE

    Sometimes we want to run the function only once and never run it again. in this situation (IFFE) Immediately Invoked…

  • Template Literals ` `

    Template Literals ` `

    With in the (backticks) ` ` the syntax is called template literals . we can embed expression in string with the…

社区洞察

其他会员也浏览了