0

Hey Stack Overflow Team,

New JS engineer here. In the DOM, why do we change formating? Curious about the significance between these two:

  1. document.querySelector('element to change').innerHTML = 'new display text.';

  2. variable.innerText = ("");

Thank you!

Haven't put it into practice yet. Reviewing examples.

Millieons
  • 1
  • 2
  • First I wouldn't call that engineer or architect but developer. Second, any half-decent developer or programmer will sue variables whenever possible. Variables allow re-using declarations instead of repeating code. It also is easier to fix as only the value of the variable needs to be changed at one point. Next, you would prefer innerText over `innerHTML` for security reasons (XSS) and performance reasons (preparing DOM). – tacoshy Feb 07 '23 at 15:46

0 Answers0