DEV Community

aryan015
aryan015

Posted on

Nullish coalescing vs Logical || by aryan

The difference between these two operators are, nullish(??) operators consider 0 and "",[],{} as a true.

Only null and undefined is considered as false.

const obj = {
name:'aryan khandelwla'
age:26
}
obj.['name'] //aryan khandelwal
obj||obj['name'] //aryan khandelwla
Enter fullscreen mode Exit fullscreen mode

?? nullish operator helps avoid repetition.[recommended]

Top comments (0)