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

143
Views
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 answers
Answer question

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 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!