JS Startup

Challenges, Tips & Tricks & Tutorials

JavaScript Quiz – can NaN be really equal to NaN

JavaScript Quiz – can NaN be really equal to NaN

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.

InShortAccording 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 – 

  1. JS Quiz – can array from method be like a map method
  2. JavaScript Quiz – Infinity number is a true or false value
  3. JavaScript Quiz – array single value comparison can be possible
  4. 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.

2 thoughts on “JavaScript Quiz – can NaN be really equal to NaN

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top
0 Shares
Share via
Copy link