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

matlab - How to equate a structure array to structure array -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -