Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 2
    \$\begingroup\$ That's a genius use of this quirk. +1 \$\endgroup\$ Commented Dec 22, 2015 at 21:05
  • \$\begingroup\$ Warning: these are not always equivalent: isNaN("string") returns true, whereas "string"!="string" returns false (obviously) \$\endgroup\$ Commented Feb 10, 2016 at 22:18
  • \$\begingroup\$ In many cases, you can even go for if(!x){, if you are detecting NaN explicitly. \$\endgroup\$ Commented Aug 9, 2016 at 21:24
  • \$\begingroup\$ More specifically, x!=x returns true only for NaN. \$\endgroup\$ Commented Dec 1, 2016 at 19:15
  • 3
    \$\begingroup\$ Casting x to number, +x!=+x, makes it equivalent to isNaN(x), yet still 2 characters shorter. Then, +"string"!=+"string" returns true. \$\endgroup\$ Commented Sep 8, 2017 at 19:50