I was checking the equality of all the falsey values from the list here:
Below code for three falsey values namely null
, undefined
and NaN
doesn't print hi
:
if(null == false) console.log('hi');
if(undefined == false) console.log('hi');
if(NaN == false) console.log('hi');
All other falsey values end up printing the text hi
as shown below:
if('' == false) console.log('hi');
if(0x0 == false) console.log('hi');
if(false == false) console.log('hi');
if(0.0 == false) console.log('hi');
if(0 == false) console.log('hi');
Can anyone help me understand the reason behind this behavior?
Update for future readers:
Three interesting reads if you are trying to wrap your head around weirdness of falsy values and equality operators in JavaScript: