Number.prototype.isInteger = Number.prototype.isInteger || function(x) {
return (x ^ 0) === x;
}
console.log(Number.isInteger(1));
will throw error in IE10 browser
The Number. isInteger() method returns true if a value is an integer of the datatype Number. Otherwise it returns false .
In JavaScript, there are two ways to check if a variable is a number : isNaN() – Stands for “is Not a Number”, if variable is not a number, it return true, else return false. typeof – If variable is a number, it will returns a string named “number”.
The Number. isInteger() method in JavaScript is used to check whether the value passed to it is an integer or not. It returns true if the passed value is an integer, otherwise, it returns false.
Definition and UsageThe isNaN() method returns true if a value is NaN. The isNaN() method converts the value to a number before testing it.
Apparently, IE treats DOM objects and Javascript objects separately, and you can't extend the DOM objects using Object.prototype.
IE doesn't let you use a prototype that is not native..
You'll have to make a separate function (global if you want) as
function isInteger(num) {
return (num ^ 0) === num;
}
console.log(isInteger(1));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With