if (count != count) {
, count NaN. :
ECMAScript , X NaN X! == X. , X NaN.
( , polyfill != !==, ).
, , isNaN? isNaN , , , NaN, , NaN . , "foo" NaN, isNaN("foo") True. , isNaN([[1]]) False, [[1]] .
count = +count || 0? , MDN . spec String.repeat :
n - ToInteger (count).
ToInteger
ToNumber ().
...
NaN, +0.
Please note that he does not say “call isNaN”, he says “if the number is NaN”, and the way to find out is to compare numberwith yourself.
Another option Number.isNaN, which, unlike the global one isNaN, does not force its argument. Number.isNaN(x)will return true if and only if x is actually NaN
Number.isNaN("foo") => false
Number.isNaN([[11]]) => false
Number.isNaN(0/0) => true
Thus, the cryptic comparison operator if (count !== count)can be replaced by if (Number.isNaN(count)).
georg source
share