Checks and returns true, if value is any kind of a "real number", a good candidate for Number():
boxed new Number('123')
BigInt (eg 123456789n or BigInt('123456789'))
Infinity
a string value that represents a "real number", eg "123" or "123.456"
Anything that is resulting to a non-NaN via Number(val), is an isAnyNumber.
NaN is NOT considered an isAnyNumber, as well as strings that would lead to NaN if we used Number(str).
In contrast, Lodash:
_.isNumber() returns true for NaN
_.isNumber() returns false for BigInt
and typeof..., well, who cares about legacy typeof, its next to useless!
Note: by "real number" we refer to the programming terminology, not the Mathematical "Real Numbers"!
See
z.isNumber() for a less inclusive, more strict check
Checks and returns true, if value is any kind of a "real number", a good candidate for
Number()
:new Number('123')
123456789n
orBigInt('123456789')
)Infinity
"123"
or"123.456"
Anything that is resulting to a non-NaN via
Number(val)
, is anisAnyNumber
. NaN is NOT considered anisAnyNumber
, as well as strings that would lead toNaN
if we usedNumber(str)
.In contrast, Lodash:
_.isNumber()
returnstrue
forNaN
_.isNumber()
returnsfalse
forBigInt
and
typeof
..., well, who cares about legacy typeof, its next to useless!Note: by "real number" we refer to the programming terminology, not the Mathematical "Real Numbers"!
See
z.isNumber()
for a less inclusive, more strict checkz.isStrictNumber()
for the most strict check