Nullish coalescing vs Logical || by aryan



This content originally appeared on DEV Community and was authored by aryan015

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

?? nullish operator helps avoid repetition.[recommended]


This content originally appeared on DEV Community and was authored by aryan015