DEV Community

Discussion on: I just created my first NPM package. It ain't much but it's honest work

Collapse
 
ispoljari profile image
Ivan Spoljaric • Edited

Ambar explained it pretty well.

I think the best, and easiest way, to check if a variable is of type 'number' in JS, is to use the

Number.isFinite(num)

method.

It will weed out anything that is not a number, including NaN and Infinity.