How crazy is hoisting?
One quick trick to find out.
function hoist(track) {
if (track === 'Billie Jean') {
action = 'dance';
} else {
action = 'chill';
}
return action;
var action;
}
hoist('Billie Jean');
console.log(action);
The variable action
still get localized to the scope of hoist
. That is the var action
works, even though it comes after return
. Note that the global scope has no access to action