0

it's always returns "Number" i already tried write like:

if n.isNaN
if n === NaN

----------but it always returns second condition ""

var n = NaN
If (n == NaN) {return " not a number"}
else return "Number"

--"Number" 
Michael Shtefanitsa
  • 303
  • 1
  • 4
  • 14
  • 2
    Use the isNaN() function. if(isNaN(n)){return 'not a number'} – Lain Nov 28 '16 at 10:40
  • Also the example works because a man compares a falsey value (NaN) with another falsey value (NaN). It is like comparing 0==0 which returns true. – Lain Nov 28 '16 at 10:43
  • You can either use the `isNaN` function or check if [`n !== n`](http://stackoverflow.com/questions/2652319/how-do-you-check-that-a-number-is-nan-in-javascript). – diiN__________ Nov 28 '16 at 10:43

1 Answers1

1

The only reliable way to check if a value is not a number in JS is by using the isNan function.

Reto
  • 1,305
  • 1
  • 18
  • 32