Skip to content

Instantly share code, notes, and snippets.

@jinlong
Created September 9, 2013 09:01
Show Gist options
  • Save jinlong/6493201 to your computer and use it in GitHub Desktop.
Save jinlong/6493201 to your computer and use it in GitHub Desktop.
变量,函数提升
//变量提升
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