Number.isFinite()
Метод Number.isFinite()
визначає, чи є передане значення скінченним числом.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Синтаксис
Number.isFinite(value)
Параметри
value
- Значення, яке треба перевірити на скінченність.
Значення, що повертається
Значення Boolean
, що вказує, чи є надане значення скінченним числом.
Опис
У порівнянні з глобальною функцією isFinite()
, цей метод не перетворює примусово значення параметра на число. Це означає, що тільки значення числового типу, які є скінченними, повернуть true
.
Поліфіл
if (Number.isFinite === undefined) Number.isFinite = function(value) {
return typeof value === 'number' && isFinite(value);
}
Приклади
Використання isFinite
Number.isFinite(Infinity); // false
Number.isFinite(NaN); // false
Number.isFinite(-Infinity); // false
Number.isFinite(0); // true
Number.isFinite(2e64); // true
Number.isFinite('0'); // false, дорівнювало б true з
// глобальною функцією isFinite('0')
Number.isFinite(null); // false, дорівнювало б true з
// глобальною функцією isFinite(null)
Специфікації
Сумісність з веб-переглядачами
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.