Created
September 9, 2013 09:01
-
-
Save jinlong/6493201 to your computer and use it in GitHub Desktop.
变量,函数提升
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 name = "Baggins"; | |
(function () { | |
// Outputs: "Original name was undefined" | |
console.log("Original name was " + name); | |
var name = "Underhill"; | |
// Outputs: "New name is Underhill" | |
console.log("New name is " + name); | |
})(); | |
//函数提升 | |
// Outputs: "Definition hoisted!" | |
definitionHoisted(); | |
// TypeError: undefined is not a function | |
definitionNotHoisted(); | |
function definitionHoisted() { | |
console.log("Definition hoisted!"); | |
} | |
var definitionNotHoisted = function () { | |
console.log("Definition not hoisted!"); | |
}; | |
// ReferenceError: funcName is not defined | |
funcName(); | |
// TypeError: undefined is not a function | |
varName(); | |
var varName = function funcName() { | |
console.log("Definition not hoisted!"); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment