Skip to content

Instantly share code, notes, and snippets.

@ralphtheninja
Last active December 10, 2015 03:58
Show Gist options
  • Save ralphtheninja/4377621 to your computer and use it in GitHub Desktop.
Save ralphtheninja/4377621 to your computer and use it in GitHub Desktop.
hoisting examples
var a = 'old value';
function dude() {
a = 'new value';
console.log('in dude:', a);
return;
function a() {};
}
dude();
console.log(a);
(function() {
try {
console.log(a);
b();
console.log(c);
d();
e();
}
catch (err) {
console.log(err.toString());
}
var a = 'myvalue';
function b() { console.log('b'); }
var c;
var d = function namedFunc() { console.log('d'); };
var e = function() { console.log('e'); };
})();
(function() {
var a = 'initial';
if (a) {
function f() { console.log('1'); }
}
else {
function f() { console.log('2'); }
}
f();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment