At the time of writing this post ES6 is not widely available on all browsers. So the purpose of this post, is to find a reliable solution to check if the variable is an integer or a float in ES5.
Number as it's common datatype.
We can find if a variable is an integer or not by using ES6's
Number.isInteger() method. But that's just available only in ES6.
The more reliable two methods to check for an Integer in ES5 are,
Please go ahead and pick one and leave the worry to the
isInt() method that we made.
Number.isInteger() method to check for Integers, we have nothing of that sort for float.
This forces us to make our custom method.
You can make it even more robust by replacing the
typeof num === 'number' and
isFinite(num) conditions with
isInfinity() methods that we made on our previous posts. You can find the links below.