I was wondering how javascript hoisting works for global variable.
Let's say I have following code snippet:
var a = 5;
function print(){
console.warn("a",a,b);
var a = 10;
b=5;
console.warn("a",a);
}
print();
In this case I am getting error "b is not defined". I wonder why Javascript hoisting is not working for global variable. I tried to look for this but getting results only for variable hoisting. Any thoughts??
b=5;
doesn't get hoisted. Onlyvar
statements do. – Carri