Number.POSITIVE_INFINITY
A propriedade Number.POSITIVE_INFINITY
representa o valor positivo infinito.
Você não precisa criar um objeto Number
para utilizar a propriedade estática (use Number.POSITIVE_INFINITY
).
Property attributes of Number.POSITIVE_INFINITY |
|
---|---|
Writable | no |
Enumerable | no |
Configurable | no |
Descrição
O valor de Number.POSITIVE_INFINITY
é o mesmo valor da propriedade Infinity
do objeto global.
Esse valor se comporta ligeiramente diferente do infinito matemático:
- Qualquer valor positivo, incluindo
POSITIVE_INFINITY
, multiplicado porPOSITIVE_INFINITY
éPOSITIVE_INFINITY
. - Qualquer valor negativo, incluindo,
NEGATIVE_INFINITY
, multiplicado porPOSITIVE_INFINITY
éNEGATIVE_INFINITY
. - Qualquer número positivo dividido por
POSITIVE_INFINITY
é Zero positivo. - Qualquer número negativo dividido por
POSITIVE_INFINITY
é Zero negativo. - Zero multiplicado por
POSITIVE_INFINITY
éNaN
. NaN
multiplicado porPOSITIVE_INFINITY
éNaN
.POSITIVE_INFINITY
, dividido por qualquer valor negativo excetoNEGATIVE_INFINITY
, éNEGATIVE_INFINITY
.POSITIVE_INFINITY
, dividido por qualquer valor positivo excetoPOSITIVE_INFINITY
, éPOSITIVE_INFINITY
.POSITIVE_INFINITY
, dividido porNEGATIVE_INFINITY
ouPOSITIVE_INFINITY
, éNaN
.
Você pode usar a propriedade Number.POSITIVE_INFINITY
para indicar uma condição de erro que retorna um número finito no caso de sucesso. Sobretudo, isFinite
seria mais apropriado nesse caso.
Exemplos
Usando POSITIVE_INFINITY
No exemplo a seguir, a variável bigNumber
recebe um valor maior que o valor máximo. Quando as declarações if
executam, bigNumber
tem o valor Infinity
, então bigNumber
recebe um valor mais gerenciável antes de continuar.
var bigNumber = Number.MAX_VALUE * 2;
if (bigNumber == Number.POSITIVE_INFINITY) {
bigNumber = returnFinite();
}
Especificação
Especificação | Status | Comentário |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Padrão | Initial definition. Implemented in JavaScript 1.1. |
ECMAScript 5.1 (ECMA-262) The definition of 'Number.POSITIVE_INFINITY' in that specification. |
Padrão | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Number.POSITIVE_INFINITY' in that specification. |
Padrão | |
ECMAScript (ECMA-262) The definition of 'Number.POSITIVE_INFINITY' in that specification. |
Padrão em tempo real |
Compatibilidade dos browsers
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.