JavaScript: what is NaN, Object or primitive?

What is NaN, object or primitive?

NaN is not a number

+5
source share
3 answers

NaNis the primitive value of a number. Just like 1, 2etc.

+4
source

This is a primitive. You can check several ways:

  • typeof NaN gives a "number", not an "object".

  • Add a property, it disappears. NaN.foo = "hi"; console.log(NaN.foo) // undefined

  • NaN instanceof Number gives false (but we know this number, so it should be primitive).

NaN , 0 / 0 NaN, . NaN , , .

+8

NaN .

NaN Not-A-Number - , Number.NaN. NaN , . , .

NaN . Math (Math.sqrt(-1)) (parseInt ( "blabla" )).

Reference

+1

All Articles