Last active
April 15, 2016 17:55
-
-
Save alexweber/a62eeaceb86029f0b7abf91884e70671 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
// Example 1 | |
var foo = 1; | |
function bar() { | |
if (!foo) { | |
var foo = 10; | |
} | |
alert(foo); | |
} | |
bar(); | |
// Example 2 | |
var a = 1; | |
function b() { | |
a = 10; | |
return; | |
function a() {} | |
} | |
b(); | |
alert(a); |
Author
alexweber
commented
Apr 15, 2016
// Same as this:
var foo = 1,
bar = function() {
if (!foo) {
var foo = 10;
}
alert(foo);
};
bar();
for(var i = 0; i < myVar.length; i++) {
(function($) {
var new = myVar.property;
// stuff
//now you can use
$.append(new)
})(jQuery);
}
This works too
for(var i = 0; i < myVar.length; i++) {
!function() {
var new = myVar.property;
// stuff
}();
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment