DEV Community

Discussion on: Javascript true false weirdness

Collapse
 
bias profile image
Tobias Nickel

and what is weired about it? I think it is super helpful. in the beginning I wrote something like this:

if (obj.prop !== undefined && obj.prop !== null) {
   ...
}

today I do

if (obj.prop) {
   ...
}

I think this is awesome.

and with the new optional chaining operator this get even better.

Collapse
 
nk2303 profile image
Ngan Kim Khong

I was confused because if "an obj is true", then "obj === true" should return true, yet I got false. At least to my humanly logic, lol. I thought something wrong with my logic until I realized it was just the equal sign.