ESlint has a rule no-restricted-globals
which by default will error on things like this isNaN
and isFinite
. If you convert these to Number.isNaN
and Number.isFinite
you will placate the Eslint machine and rainbows and unicorns will appear.
Unfortunately this is JavaScript, and any assumption about things that look like they should be the same can trip you up.
Number.isFinite vs isFinite
Number.isFinite() does not convert the values to a Number, and will not return true for any value that is not of the type Number.
https://www.w3schools.com/jsref/jsref_isfinite_number.asp
This makes no sense to me, and if someone had to guess having not used JavaScript previously they may assume that Number.isFintite()
would convert to a number. But its JavaScript, so throw away these types of assumptions.
Number.isNaN vs NaN
Number.isNaN() is different from the global isNaN() function. The global isNaN() function converts the tested value to a Number, then tests it.
Number.isNaN() does not convert the values to a Number, and will not return true for any value that is not of the type Number.
https://www.w3schools.com/jsref/jsref_isnan_number.asp
TLDR
Be careful trying to placate the ESlint machine. Global functions and global constructor methods of the same name are not guaranteed to produce the same result.