0
 function openMenu() {
  var menu = document.getElementById("menu")
  var num = 123
  menu.classList.remove("hidden")
}

function closeMenu() {
  menu.classList.add("hidden")
  console.log(num)  
}

https://jsfiddle.net/kn5ateov/

I thought i knew hoisting, now I know, I know nothing. How come the second function has access to the var menu but not the var num?

  • It doesn't. The second function has access to a different, global, variable with the same name. – Quentin Aug 25 '21 at 16:17

0 Answers0