Q: Difference between var and const in document.getElementById() When I store document.getElementById in var I can't change innerText
var status = document.getElementById('status');

// This doesn't work (nothing changes in the element)
function change() {
    status.innerText = "Ready.";
}

But when I store it in const I can. Why?
const status = document.getElementById('status');

// This works
function change() {
    status.innerText = "Ready.";
}


A: Elements declared with var on the top level get assigned to the global object. When you do var status =, you assign to window.status - but window.status is reserved and must always be a string. So, the result of document.getElementById('status'); is converted into a string when assigned.
Variables declared with const, in contrast, do not get assigned to the global object when on the top level, so the problems with window.status do not appear.
Another solution would be to write your code inside an IIFE:
(() => {
  var status = document.getElementById('status');
  function change() {
    status.innerText = "Ready.";
  }
})();

Or use a different variable name than status.
