DEV Community

aryan015
aryan015

Posted on • Updated on

Nullish coalescing vs Logical || by aryan

Correction from previous post with same name.❤

The difference between these two operators are, nullish(??) operator consider false, 0 and "" as a true.

Only null and undefined is considered as false.

const obj = {
name:'aryan khandelwal'
age:26
}
obj?.['name'] //aryan khandelwal // only access 'name' when objest is defined.
obj||obj['name'] //aryan khandelwal
Enter fullscreen mode Exit fullscreen mode

note: Even false is considered as true🤷‍♀️

🔗linkedin

learning resources

🧡Scaler - India's Leading software E-learning
🧡w3schools - for web developers

Top comments (0)