This is an experimental technology, part of the Harmony (EcmaScript 6) proposal.
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future version of browsers as the spec changes.
Summary
Determine whether the passed value is an integer.
Method of Number |
|
|---|---|
| Implemented in | JavaScript 1.8.5+ |
| ECMAScript Edition | ECMAScript 6th Edition |
Syntax
Number.isInteger(testValue)
Parameters
-
testValue - The value to be tested for being an integer.
Description
Determine whether the passed value is an integer. If the target value is an integer, return true, otherwise return false.
Example
alert([ Number.isInteger(0.1), Number.isInteger(1), Number.isInteger(Math.PI) ]);
Polyfill
The following algorithm matches the one specified in ECMA harmony:
/*\
|*|
|*| :: Number.isInteger() polyfill ::
|*|
|*| https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
|*|
\*/
if (!Number.isInteger) {
Number.isInteger = function isInteger (nVal) {
return typeof nVal === "number" && isFinite(nVal) && nVal > -9007199254740992 && nVal < 9007199254740992 && Math.floor(nVal) === nVal;
};
}
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 25.0 FIXME: ? | 15.0 (15) | Not supported | Not supported | Not supported |
| Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | Not supported | 15.0 (15) | Not supported | Not supported | Not supported |
Mozilla Developer Network