I can't seem to find a difference in results when using Number.isFinite()
and Number.isInteger()
. I get that finite means not infinity, but Number.isInteger(Infinity)
returns false
too, so when do these two methods actually differ in their results?
Comparing the outcomes for all these values and they produce the same results, so I'm stumped as to why both methods exist:
[0, 1, -1, '1', Infinity, -Infinity, NaN, true, false, {}, null, undefined].forEach(val => {
const string = typeof val === 'string' ? `"${val}"` : val === null ? `null` : typeof val === 'object' ? `{}` : val;
console.log(`Number.isFinite(${string}): ${Number.isFinite(val)}`)
console.log(`Number.isInteger(${string}): ${Number.isInteger(val)}`)
})
Via Active questions tagged javascript - Stack Overflow https://ift.tt/exsVIwp
Comments
Post a Comment