
Not A Number (NaN) –
NaN property stands for “Not A Number” value. This indicates that a value is not a legal number. So NaN can be equal to NaN
In order to check number is a legal number use the isNaN() global function.
NaN property syntax –
Number.NaN
isNaN() Function Syntax –
isNaN()
For more detail about Not a Number NaN click here.
JavaScript Question
In this javascript quiz, find out NaN can be really equal to NaN but is Not a Number is not a legal number that can not be matched together.
First, declare a variable valueOne using the let keyword and assign NaN value to it.
let valueOne = NaN;
First, declare another variable valueTwo using the let keyword and assign NaN value to it.
let valueTwo = NaN;
Now, comparing an valueOne and valueTwo together with equal and typed equal.
console.log(valueOne == valueTwo);
console.log(valueOne === valueTwo);
Any idea, what should be the output of above console log statement.
Answer – false, false
Click To Run Code
Explanation
Now, you know the answer is false, false. But why as they both looks same. Let me explain.
InShort – According to IEEE 754 specifications any operation performed on NaN values should yield a false value or should raise an error.
So, NaN gives false output when compare with NaN. If NaN not equal to NaN.
Then typed equal also gives the false output.
console.log(valueOne == valueTwo); // false
console.log(valueOne === valueTwo); // false
At last, That’s why we get an answer “false, false“.
Let me know in the comment section, what you think about it.
I hope you understand the concept and logic behind it.
But wait, i have something more for you –
Check out our other javascript quiz –
- JS Quiz – can array from method be like a map method
- JavaScript Quiz – Infinity number is a true or false value
- JavaScript Quiz – array single value comparison can be possible
- JS Quiz – compare the self value with data type
Conclusion
To participate in our javascript quiz or challenges, tutorial, tips & tricks make sure to join our jsstartup newsletter. So, you can able to participate in our daily challenges & learn the javascript concept.
And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page
If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.
Thanks for the compliment. I am trying my best to deliver what I could to do.
you are in point of fact a good webmaster. The website loading speed is
amazing. It sort of feels that you are doing any unique
trick. In addition, The contents are masterpiece.
you’ve performed a fantastic activity on this subject!
Hey There. I found your blog using msn. This is a really well written article.
I’ll make sure to bookmark it and return to read more of
your useful info. Thanks for the post. I’ll certainly comeback.
I just want to mention I am just all new to weblog and seriously enjoyed this web-site. More than likely I’m planning to bookmark your website . You amazingly come with exceptional article content. Bless you for revealing your website.
Saved as a favorite, I like your website!
Very good article! We are linking to this great post on our site. Keep up the good writing.