r/ProgrammerHumor • • Jun 21 '18

Thanks Brendan for giving us the Javascript

Post image
3.1k Upvotes

302 comments sorted by

View all comments

Show parent comment

27

u/FisHBoNe19 Jun 21 '18

[] == false

![] == false // I don't know why

!+[] == true

8

u/tofiffe Jun 21 '18

This just raises further questions

5

u/KillTheBronies Jun 21 '18

[] == false

== calls toPrimitive if the types are different, so that becomes '' == false

![] == false // I don't know why

! calls toBoolean first, which returns true for objects

!+[] == true

Not sure on this one, I think it casts to '' then 0?

1

u/dconman2 Jun 21 '18

+[] casts to Number (0) then !0 casts to Boolean (false) then negates (true)

4

u/aboardthegravyboat Jun 21 '18

this is more wtf than anything in the pic