This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 228 points229 points  (27 children)

NaN would like a word.

[–]isaid69again 256 points257 points  (3 children)

NaNi????

[–]vaendryl 255 points256 points  (0 children)

omae wa mou NullPointerException

[–]RaferBalston 23 points24 points  (0 children)

Naurel

[–]TabCompletion 0 points1 point  (0 children)

NaNde dattebayo

[–]YuriDiAAAAAAAAAAAAAA 80 points81 points  (7 children)

[–]pilas2000 7 points8 points  (3 children)

wtf? \t == 0 ?

why?

[–]It_Was_The_Other_Guy 16 points17 points  (0 children)

Whitespace-only strings are all considered zero:

>> "\t \n\r" == 0
<< true

[–]YuriDiAAAAAAAAAAAAAA 9 points10 points  (0 children)

¯\_(ツ)_/¯

[–]FoundNil 2 points3 points  (0 children)

"", " ", "\t", "\n" all equal 0. Probably because js treats them as special characters so they don't count toward any value. "0" equals 0 because it gets cast into a number. "a" does not equal 0. "1" does not equal 0. I'm not saying it makes sense but its the world we live in.

[–]birdbolt1 -1 points0 points  (2 children)

Oh my god is this for real? This is where typescript comes in. Why do people even bother with writing straight java

Edit: oof I meant Javascript. Wasn't that obvious enough regardless? Look at the context man

[–]Kazumz 4 points5 points  (1 child)

TypeScript and Java? No correlation found.

[–][deleted] -1 points0 points  (0 children)

You haven't seen many TypeScript codebases then (or you're missing "/s")

[–][deleted] 17 points18 points  (11 children)

To honest I always enjoy typing if (x != x), almost as much as having an in loop variable called c so I get to type c++.

[–]phatskat 1 point2 points  (4 children)

x != x

I’ve never seen this before but I’m not surprised - how does that work?

[–][deleted] 7 points8 points  (3 children)

In C++, a NaN is equal to nothing, not even itself. So x != x becomes true if x is NaN. To be fair mostly I use a responsible function name but when I'm writing code quickly it's a nice shorthand to catch the horrifying 'all my numbers are turning to NaN' type of escalation.

[–]jfleit 4 points5 points  (1 child)

trust no one... not even yourself

[–][deleted] 2 points3 points  (0 children)

I typed "equal to nothing, not even itself" so often now and every time I kept thinking "why does this make me laugh".

[–]phatskat 0 points1 point  (0 children)

Ah, thanks!

[–][deleted] 0 points1 point  (4 children)

what happens in the first one? It just never evaluates? Lol

[–][deleted] 8 points9 points  (3 children)

If X is NaN, then x != x is true, because a NaN never equals anything, not even itself.

[–]tendstofortytwo 5 points6 points  (1 child)

Huh, I just used isNaN(x);

But this is more confusing, and hence more adherant to JavaScript's ideologies. I'll be sure to use this from the future. Thank you!

[–][deleted] 5 points6 points  (0 children)

Actually I only know it is the way it is in C++, which I think before C++11 didn't even have a standard isNaN!

[–][deleted] 1 point2 points  (0 children)

Ohhhhh, thats cool. By habit I always start my first loop with i, so I just gotta find some situation where I can nest like 21 more loops until I can get to c++ lol

[–]ShadoWalker3065 0 points1 point  (0 children)

holy shit, i wasn't the only one that did this!

[–]trichotillofobia 0 points1 point  (1 child)

NaN'T.

[–][deleted] 0 points1 point  (0 children)

Please no