Javascript isNaN and null

In javascript

parseInt(null)returns a NaN
parseNumber(null)also returns aNaN

isNaN('abcd')returns truebecause "abcd" is certainly not a number,
isNaN(5)returnsfalse

but strange

isNaN(null)returns falsethat is odd, as this is a number, but, as we saw in parseNumber, it can be seen asNaN

There seems to be an inconsistency between how the zero is scanned parseInt, and through isNaNit it sees it as NaN, and the other sees it as Number. Why are they incompatible?

+4
source share
1 answer

The first thing that happens in isNaN()is that the argument is forced to a number. That is, as if the function looked like this:

function isNaN(n) {
    n = +n;
    // ...
}

null , 0. NaN.

isNaN , , ; , . , , - , , - NaN.

Number.isNaN(), . , , null   NaN.

+3

Source: https://habr.com/ru/post/1692393/


All Articles