Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
InnerHTML para nulo vs indefinido

Considere este fragmento

 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}"`);

¿Por qué el primer fragmento de innerHTML no produce "null" ? Esperaba que el valor fuera el resultado de innerHTML = value igual que String(value) como espera un DOMString ? String(null) produce "null" .

MDN también menciona el enfoque ToString que también devuelve "null" . Lo único que podría insinuar este comportamiento especial es este fragmento de la página en DOMString

Ciertas API web que aceptan un DOMString tienen un comportamiento heredado adicional, en el que pasar una cadena nula se convierte en la cadena vacía en lugar del "nulo" habitual.

¿Hay algún lugar definitivo (especificación o de otro tipo) desde donde se pueda confirmar tal comportamiento?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Sí, hay una especificación: https://w3c.github.io/DOM-Parsing/#the-innerhtml-mixin

innerHTML tiene el "atributo extendido IDL" LegacyNullToEmptyString que describe este comportamiento.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!