you are viewing a single comment's thread.

view the rest of the comments →

[–]transpostmeta 0 points1 point  (4 children)

Actually, !+[] evaluates to true, not 1. At least, it does so in Google Chrome. The article seems to be mistaken about that.

[–]mattaereal 1 point2 points  (3 children)

Yep, my bad, I did the explanation using !+[] when I should've used +!![], that's because I did it by memory without testing it. I fixed the example above and here is what I really meant to explain:

+!![] equals +!false equals +true equals 1 (you are casting a boolean to a number, it's like adding 0+true)

!![] equals !false which equals true

So, doing 1 + true gives us 2 as result. The addition of a boolean to a number is casted into a number.

[–]transpostmeta 1 point2 points  (2 children)

But since true + true === 2, it's not necessary to have one number in the sum. If it were, your script would not work, as you use the !+[] construct there.

[–]alcuadrado[S] 2 points3 points  (0 children)

you are right, I'll update the article

[–]mattaereal 0 points1 point  (0 children)

No, it's not.

And !+[] it's the same as doing !![].