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

144
Visualizações
InnerHTML for null vs undefined

Consider this snippet

const div = document.createElement('div');
div.innerHTML = null; // 1
console.log(`After setting null: "${div.innerHTML}"`);
div.innerHTML = undefined; // 2
console.log(`After setting undefined: "${div.innerHTML}"`);

Why doesn't the first snippet of innerHTML yield "null"? I expected the value to be a result of innerHTML = value to be same as String(value) as it expects a DOMString? String(null) yields "null".

MDN also mentions the ToString approach which too returns "null". The only thing that might hint at this special behavior is this snippet from the page on DOMString

Certain Web APIs accepting a DOMString have an additional legacy behavior, where passing null stringifies to the empty string instead of the usual "null".

Are there any definitive places (spec or otherwise) where such behavior can be confirmed from?

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

0

Yes, there is a spec: https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin

innerHTML has the "IDL extended attribute" LegacyNullToEmptyString which describes this behavior.

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