What would be the explanation for the strange javascript expression? -
in javascript following line of code gives answer 1
+ ! {} [true] i couldn't understand how?
any gurus explanation appreciated.
{} empty object.
so {}[0] or {}[true] or {}[1] etc.. undefined
adding ! casts {}[0] boolean, returning opposite. (undefined becoming false, therefore returns true).
adding + casts int, true becomes 1.
Comments
Post a Comment