MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/8srix1/thanks_brendan_for_giving_us_the_javascript/e11rpxi/
r/ProgrammerHumor • u/[deleted] • Jun 21 '18
302 comments sorted by
View all comments
Show parent comment
27
[] == 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!+[] == trueNot 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
8
This just raises further questions
5
== calls toPrimitive if the types are different, so that becomes '' == false
==
toPrimitive
'' == false
! calls toBoolean first, which returns true for objects
!
toBoolean
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)
1
+[] casts to Number (0) then !0 casts to Boolean (false) then negates (true)
4
this is more wtf than anything in the pic
View all comments
Show parent comment
27
u/FisHBoNe19 Jun 21 '18
[] == false
![] == false // I don't know why
!+[] == true