0

How come a gets logged and b doesn't? Is a somehow appended to the global scope, while b remains within hoist() scope?

function hoist() {
  a = 20;
  var b = 100;
}

hoist();

console.log(a);
// Output: 20

console.log(b);
// Output: ReferenceError: b is not defined
L_Fr
  • 99
  • 6
  • 3
    `b` is only in-scope of the function. Not in global scope. `a` is an implicit global. Also, hoisting is entirely unrelated to any of this. – VLAZ Dec 13 '21 at 07:52

0 Answers0