Created
November 29, 2014 09:00
-
-
Save d8ta/c96ba0fd0bf37be74fa3 to your computer and use it in GitHub Desktop.
hosting example
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 test = 'hello'; //window, global var | |
(function() { | |
//function scope, but we can also access variables and functions in the global scope | |
//where this function was defined (thus test) and the variables of the parent function | |
console.log(test); //ToDo: wird in der console als undefined ausgegeben, warum? | |
//function declaration statement, function declarations get hoisted to top of function scope | |
function test2(param2, param3) { | |
console.log(test); | |
} | |
//function expression | |
var test3 = function(param2, param3) { | |
console.log(test); | |
}; | |
var test = 'hello2'; | |
test2(); | |
test3(); | |
//hoisting: | |
//all declarations get hoisted (variable and function) | |
//thus it would be the same to move the variable declaration | |
//on top of function scope. | |
//hoisting happens before any code is executed | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment