Skip to content

Instantly share code, notes, and snippets.

@tsiege
Created November 11, 2014 16:06
Show Gist options
  • Save tsiege/7ee3589898ea81d0453f to your computer and use it in GitHub Desktop.
Save tsiege/7ee3589898ea81d0453f to your computer and use it in GitHub Desktop.
Hoisting examples
// what's hoisted
// var carName (just the variable name is hoisted)
// driveCar (whole function is hoisted because driveCar is a function declaration)
// var parkCar (just the variable name is hoisted because parkCar is a function expression)
console.log(carName);
// -> undefined
driveCar(carName);
// -> driving undefined
parkCar(carName);
// -> TypeError: undefined is not a function
var carName = "volvo";
// function declaration
function driveCar(carName){
console.log('driving ' + carName);
}
// function expression
var parkCar = function(carName){
console.log('parking ' + carName);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment