O método Number.isInteger()
determina se o valor passado é um inteiro.
Sintaxe
Number.isInteger(valor)
Parâmteros
valor
- O valor a ser testado por ser um inteiro.
Descrição
Se o valor a ser testado for um inteiro, retorna true
, senão retorna false
. Se o valor for NaN
ou infinito, retorna false
.
Exemplos
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;
};
Especificações
Especificação | Estado | Comentário |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Number.isInteger' in that specification. |
Standard | Definição inicial. |
Compatibilidade dos browsers
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Funcionalidade | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Suporte básico | (Yes) | 16 (16) | No support | (Yes) | No support |
Funcionalidade | Android | Chrome para Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Suporte básico | No support | No support | 16.0 (16) | No support | No support | No support |
Ver também
- O objecto
Number
ao qual pertence.