Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
Are null and Infinity interchangeable in Javascript?

I'm setting max to Infinity on this object:

let RANGE_DEFAULT_OPTIONS: any = { min: 0, max: Infinity };
console.log(RANGE_DEFAULT_OPTIONS); // {min: 0, max: null}

When the RANGE_DEFAULT_OPTIONS object is logged, it logs null for the max property.

Here's the Stackblitz Demo

Also this will log true:

console.log(RANGE_DEFAULT_OPTIONS.max === Infinity);

So are Infinity and null interchangeable?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

No, they’re not.

Normally, console.log(…) called with an object, prints the object intact:

enter image description here

const obj = { min: 0, max: Infinity };

console.log(obj);

In the case of StackBlitz, there’s probably a call to JSON.stringify(…) somewhere down there, which messes things up (which is sad, IMO):

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório

0

Here's the same code in a snippet you can run in your browser. As you can see, Infinity and null are not equal.

let RANGE_DEFAULT_OPTIONS = { min: 0, max: Infinity };
console.log(RANGE_DEFAULT_OPTIONS);
console.log('strict equality', Infinity === null);
console.log('loose equality', Infinity == null);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda