Greeting All,

I hope you all are doing awesome. NaN stands for “Not a Number” in core JavaScript and isNaN() is a function which returns a boolean value by checking whether passing argument is exactly a NaN or not.

Welcome back, I am very excited about this blog and pretty sure after finishing, you will also be found yourself in the same position. Many of us already know that isNaN() is a globally available function in JavaScript which scope is bound to window object. Only a few of us are aware of that isNaN() is also available in a prototype of Number’s constructor function.

Sounds a bit difficult? Not an issue. Let’s simplify this by our favorite section of the blog which is nothing but code section.

Outputs are little interesting. isn’t it? 🙂 🙂

I know, your mind is jumping with question i.e. “how they are giving different outputs?” That is the exact thing which we will discuss here. Let’s start.

1. window().isNaN():  An argument passed in window.isNaN(), first converts it to the number then performs checking on it. Let’s try to understand above example.

In above case, we are passing blank as a parameter it means passed argument not defined. It will be converted as window.isNaN(Number(undefined)). If we check Number(undefined) on the console then it’s output is NaN. Now, function became as window.isNaN(NaN) which will be definitely true. Got it. 

2. Number.isNaN(): The argument passed in Number.isNaN()  only performs checking on it, not any type conversion. Let’s try to understand above example again.

Number.isNaN() will translated into Number.isNaN(undefined) as passed argument is not defined. And obviously, it will be returned as false because undefined in not NaN. You can check undefined == NaN on your console which will return false.

Let’s take some other examples:

 

Hey! congratulation dude, you have done with it. Now you can perform checking on the numbers by your own preferences. This blog give some more arrows in your bow.

Thanking you all,

Any type of feedback or comment is really appreciated. I am eagerly waiting for those.

Hope to see you soon, until then Happy Learning …… 🙂 🙂 🙂