Only Variable declarations, not the assignment are hoisted, or moved to the top of their available scope
console.log(x); var x = 5; console.log(x); console.log(y);
var x; console.log(x); // -> undefined x = 5; console.log(x); // -> 5 console.log(y); // -> Uncaught ReferenceError: y is not defined
console.log(x); console.log(y); var x = 'This will log "undefined"!'; y = 'This will throw an error :(';
Are you interested in this?
If you have questions, please ask me...
And if this is okay, I am going to explain about Function Hoisting
Thank you !