Last active
December 10, 2015 03:58
-
-
Save ralphtheninja/4377621 to your computer and use it in GitHub Desktop.
hoisting examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = 'old value'; | |
function dude() { | |
a = 'new value'; | |
console.log('in dude:', a); | |
return; | |
function a() {}; | |
} | |
dude(); | |
console.log(a); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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'); }; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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