MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/21ezh3/javascript_equality_table/cgd4sjk/?context=3
r/programming • u/vz0 • Mar 26 '14
331 comments sorted by
View all comments
Show parent comments
31
I think it's pretty reasonable to mistakenly assume that something that == false won't cause execution :p
59 u/coarsesand Mar 27 '14 In another language, yes, but the == operator in JS is special (in the shortbus sense) because it does type conversion. If you wanted to get the actual "truthiness" of "0", you'd use the ! operator instead.!!"0" > true 18 u/no_game_player Mar 27 '14 Gilded for best "javascript is fucked up" in a nutshell I've seen. 2 u/Confusion Mar 27 '14 This is actually a common way to coerce something into the 'appropriate' boolean value in several languages. At least Ruby and Python come to mind. → More replies (1)
59
In another language, yes, but the == operator in JS is special (in the shortbus sense) because it does type conversion. If you wanted to get the actual "truthiness" of "0", you'd use the ! operator instead.
"0"
!!"0" > true
18 u/no_game_player Mar 27 '14 Gilded for best "javascript is fucked up" in a nutshell I've seen. 2 u/Confusion Mar 27 '14 This is actually a common way to coerce something into the 'appropriate' boolean value in several languages. At least Ruby and Python come to mind. → More replies (1)
18
Gilded for best "javascript is fucked up" in a nutshell I've seen.
2 u/Confusion Mar 27 '14 This is actually a common way to coerce something into the 'appropriate' boolean value in several languages. At least Ruby and Python come to mind. → More replies (1)
2
This is actually a common way to coerce something into the 'appropriate' boolean value in several languages. At least Ruby and Python come to mind.
→ More replies (1)
31
u/[deleted] Mar 26 '14
I think it's pretty reasonable to mistakenly assume that something that == false won't cause execution :p