I have this output in the console:
console.log((!undefined)==(!false)) // true (fine)
console.log((!!undefined)==(!!false)) // true (still fine)
As I know, !!x==x, isn’t it?
console.log((undefined)==(false)) // false
Can anyone tell me why this returns false?
Is not true that !!false==false and !!undefined==undefined?
Yes.
!!xdoes not return x.!undefinedcoercesundefinedto a boolean,false, then finds!((bool)undefined)=!false, if we use C++ cast notation. So!!undefinedgives!!((bool)undefined)=!!(false)=!true=false, rather thanundefined.