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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -