Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What means ( value unequal value ) in JavaScript?

Tags:

javascript

I've seen these snippet in the polyfill shown on this MDN-documentation:

 // Casts the value of the variable to a number.
 // So far I understand it ...
 count = +count;
 // ... and here my understanding ends.
 if (count != count) {
   count = 0;
 }

I got no idea about the purpose.

How can something be unequal itself?

like image 869
cluster1 Avatar asked Dec 18 '22 19:12

cluster1


2 Answers

In JavaScript NaN is the only value that's not equal to itself. So that's a check for NaN.

like image 117
DenizEng Avatar answered Jan 10 '23 09:01

DenizEng


This is the test when count is NaN because only NaN != NaN.

like image 29
jcubic Avatar answered Jan 10 '23 09:01

jcubic