Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda