Number.isInteger()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
O método Number.isInteger()
determina se o valor passado é um inteiro.
Experimente
function fits(x, y) {
if (Number.isInteger(y / x)) {
return "Fits!";
}
return "Does NOT fit!";
}
console.log(fits(5, 10));
// Expected output: "Fits!"
console.log(fits(5, 11));
// Expected output: "Does NOT fit!"
Sintaxe
Number.isInteger(value)
Parâmetros
value
-
O valor a testar se é um inteiro.
Valor retornado
Um Boolean
indicando se o valor é inteiro ou não.
Descrição
Se o alvo for um inteiro, retorna true
, senão retorna false
. Se o valor é NaN
ou infinito, retorna false
.
Exemplos
js
Number.isInteger(0); // true
Number.isInteger(1); // true
Number.isInteger(-100000); // true
Number.isInteger(0.1); // false
Number.isInteger(Math.PI); // false
Number.isInteger(Infinity); // false
Number.isInteger(-Infinity); // false
Number.isInteger("10"); // false
Number.isInteger(true); // false
Number.isInteger(false); // false
Number.isInteger([1]); // false
Polyfill
js
Number.isInteger =
Number.isInteger ||
function (value) {
return (
typeof value === "number" &&
isFinite(value) &&
Math.floor(value) === value
);
};
Especificações
Specification |
---|
ECMAScript® 2025 Language Specification # sec-number.isinteger |
Compatibilidade com navegadores
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
isInteger |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Ver tabém
- O objeto
Number
a qual este método pertence.