Why typeof NaN is number? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Why typeof NaN is number?

1st May 2019, 2:42 PM
Francis Abad
Francis Abad - avatar
4 Respostas
+ 7
That has to do with how floating point numbers work. I don't know if you know binary so I won't go into much detail, but basically a NaN is a floating point number like any other. It just does not represent a value.
1st May 2019, 3:03 PM
Schindlabua
Schindlabua - avatar
+ 13
**Interesting facts about JavaScript numbers: ā€¢ JavaScript implements a standard called "floating point math". Their decimal part offers more precision closer toĀ 0, and less precision further away from it. We can say the decimal point is "floating". ā€¢ Numbers resulting from invalid math operations like 1/0 or 0/0 are special. NaNĀ is one of such special numbers. ā€¢ typeof(NaN) is a number because it is a numeric value. Itā€™s called "Not a Number" because it represents the idea of an "invalid" number.
26th Feb 2020, 2:58 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 4
Only the god knows šŸ˜‚
1st May 2019, 2:53 PM
Seniru
Seniru - avatar
+ 2
NaN means unknown number. It's without a value. Like 0 but without a value. So it's from number type.
1st May 2019, 5:42 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar