Javascript Hoisting For Global Variable
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;
Solution 1:
var
statements are hoisted. function declarations are hoisted. Assignments are not hoisted (to the extent that if you combine a var
statement with an assignment (var foo = 1
) then the declaration part is hoisted but the assignment is not).
Post a Comment for "Javascript Hoisting For Global Variable"