Metoda Number.isInteger()
sprawdza czy wpisana wartość jest liczbą całkowitą.
Syntax
Number.isInteger(value)
Parametry
zmienna
- Zmienna będzie testowana jako liczba.
Zwracana wartość
Metoda zwraca wartość typu Boolean
.
Opis
Jeśli sprawdzana zmienna jest liczbą całkowitą metoda zwraca true
, w innym przypadku zwraca false
. Jeśli zmienna jest typu NaN
lub spoza zakresu metoda zwraca false
.
Przykłady
Number.isInteger(0); // true
Number.isInteger(1); // true
Number.isInteger(-100000); // true
Number.isInteger(0.1); // false
Number.isInteger(Math.PI); // false
Number.isInteger(NaN); // 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
Number.isInteger = Number.isInteger || function(value) {
return typeof value === 'number' &&
isFinite(value) &&
Math.floor(value) === value;
};
Dokumentacja
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Number.isInteger' in that specification. |
Standard | Initial definition. |
ECMAScript (ECMA-262) The definition of 'Number.isInteger' in that specification. |
Living Standard |
Kompatybilne przegladarki
BCD tables only load in the browser
The compatibility table in 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.
Sprawdź również
- Metoda ta należy do klasy
Number
.