consider these slightly two different versions of hoisting...
mylocation = \"dublin\"
function outputPosition() {
alert(mylocation);
mylocation = \"fing
Take for example :
x = 5;
var x;
console.log( x );
Technically you might want to look at x = 5;
as a wrong statement in this context considering the fact that it comes before the declaration, but the JS Engine doesn't work that way. It sees x = 5
and var x
as two separate statements, the first one a compiler-related task, and the second one an execution-related task.
what this means in simple terms is that all declarations in a scope, regardless of where they appear, are processed first before the code itself is executed. i.e you can execute a variable before declaring it.