I saw this strange piece of code !{}[true]; today. When you run this code snippet, it returns true.
What full !{}[true] means and why it returns true.
>>>!{}[true];
'true'
I saw this strange piece of code !{}[true]; today. When you run this code snippet, it returns true.
What full !{}[true] means and why it returns true.
>>>!{}[true];
'true'
{}[true] returns undefined because {} has no property "true" (!{"true":25}[true] would return false).
So !{} is true.
Negate an object? How exactly do you negate an object?
In any case, start with {}[true]. What that does is create a new object, and reference its true member, which doesn't exist, so returns undefined.
So then you have !undefined, which evaluates to true.