This is a new technology, part of the ECMAScript 2015 (ES6) standard .
This technology's specification has been finalized, but check the compatibility table for usage and implementation status in various browsers.
El mètode Number.isInteger() determina si el valor que se li passa és un nombre sencer.
Sintaxi
Number.isInteger(valor)
Paràmetres
valor- El valor que serà comprovat si és sencer o no.
Descripció
Si el valor passat és un nombre sencer, la funció retornarà true, en cas contrari es retorna false. Si el valor és NaN o infinit, es retorna false.
Exemples
Number.isInteger(0.1); // false
Number.isInteger(1); // true
Number.isInteger(Math.PI); // false
Number.isInteger(-100000); // true
Number.isInteger(NaN); // false
Number.isInteger(0); // true
Number.isInteger("10"); // false
Polyfill
Number.isInteger = Number.isInteger || function(value) {
return typeof value === "number" &&
isFinite(value) &&
Math.floor(value) === value;
};
Especificacions
| Especificació | Estat | Comentaris |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Number.isInteger' in that specification. |
Standard | Definició inicial. |
Compatibilitat amb navegadors
| Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Suport bàsic | (Yes) | 16 (16) | Not supported | (Yes) | Not supported |
| Característica | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Suport bàsic | Not supported | Not supported | 16.0 (16) | Not supported | Not supported | Not supported |
Vegeu també
- L'objecte
Numberal que pertany.