Why Is Isfinite(undefined) != Isfinite(null)?
Why is the value for undefined considered Finite in javascript while null is not? This is a very basic question, which has thwarted my googlefoo (too much noise). isFinite(undefine
Solution 1:
This is because Number(null) === 0
.
Solution 2:
isFinite (number)
Returns false if the argument coerces to NaN, +∞, or −∞, and otherwise returns true.
isFinite
convert input using Number()
and:
Number(undefined); //== NaNNumber(null); //== 0
that is the reason undefined is false and null is true for isFinite.
If you try:
isFinite(!undefined); // true
because undefined is NaN and on negating it it converted to 1 which is finite.
Post a Comment for "Why Is Isfinite(undefined) != Isfinite(null)?"