Why Does "typeof NaN" return "number" in JavaScript?

Find out why typeof NaN returns 'number' in JavaScript

The concept of NaN being a number is not exclusive to JavaScript. In fact, it is a widely used numeric data type value in computing which is meant to represent undefined or unrepresentable mathematical values (such as 0/0, etc.):

0/0; // NaN

Math.sqrt(-1); // NaN
Math.log(-1); // NaN

// ...

NaN is actually, rarely used in a program. It is typically returned from a function or operation to indicate a failed operation on numbers. It is used to suggest that the value is not a legal number (where you may be expecting the return value to be a legal number).

Hope you found this post useful. It was published . Please show your love and support by sharing this post.