Number.POSITIVE_INFINITY
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since julio de 2015.
Resumen
La propiedad Number.POSITIVE_INFINITY representa el infinito positivo.
No se tiene que crear un objeto Number para acceder a esta propiedad estática (use Number.POSITIVE_INFINITY).
Atributos de la propiedad Number.POSITIVE_INFINITY | |
|---|---|
| Sobrescribir | No |
| Numerable | No |
| Configurable | No |
Descripción
El valor de Number.POSITIVE_INFINITY es el mismo valor de la propiedad Infinity del objeto global.
Este valor tiene un comportamiento ligeramente diferente al infinio matemático:
- Cualquier valor positivo, incluyendo
POSITIVE_INFINITY, multiplicado porPOSITIVE_INFINITYda como resultadoPOSITIVE_INFINITY. - Cualquier valor negativo, incluyendo
NEGATIVE_INFINITY, multiplicado porPOSITIVE_INFINITYda como resultadoNEGATIVE_INFINITY. - Cero multiplicado por
POSITIVE_INFINITYda como resultado NaN. - NaN multiplicado por
POSITIVE_INFINITYda como resultado NaN. POSITIVE_INFINITY, dividido por cualquier valor negativo exceptoNEGATIVE_INFINITY, da como resultadoNEGATIVE_INFINITY.POSITIVE_INFINITY, divido por cualquier valor positivo exceptoPOSITIVE_INFINITY, da como resultadoPOSITIVE_INFINITY.POSITIVE_INFINITY, divido porINFINITYo porPOSITIVE_INFINITY, da como resultado NaN.- Cualquier numero divido por
POSITIVE_INFINITYda como resultado cero.
Muchos métodos de JavaScript (tales como el constructor del objeto Number, parseFloat y parseInt) retornan NaN si el valor especificado en el parámetro es signficativamente mayor a Number.MAX_VALUE.
Podrías utilizar la propiedad Number.POSITIVE_INFINITY para indicar una condición de error que retorne un numero finito en caso de que esto suceda. Note, sin embargo, que isFinite seria mas apropiado en estos casos.
Ejemplo
En el siguiente ejemplo, a la variable bigNumber se le asigna un valor mucho mayor al valor máximo. Cuando la sentencia if es ejecutada, bigNumber tiene el valor "Infinity", por lo cual a bigNumber le es asignado un valor mas manejable antes de continuar.
var bigNumber = Number.MAX_VALUE * 2;
if (bigNumber === Number.POSITIVE_INFINITY) {
bigNumber = returnFinite();
}
Especificaciones
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-number.positive_infinity> |
Compatibilidad con navegadores
Loading…