Skip to content

Instantly share code, notes, and snippets.

View lenafaure's full-sized avatar

Lena Faure lenafaure

View GitHub Profile
rockStar = “Mick Jagger”;
var rockStar;
console.log(rockStar); // Prints “Mick Jagger”
console.log(rockStar); // Prints “undefined”
var rockStar = “Mick Jagger”;
var rockStar;
rockStar = “Mick Jagger”;
var rockStar;
console.log(rockStar);
rockStar = “Mick Jagger”;
function movieStar() { // function declaration is moved to the top of the global scope
  var name; // variable declaration is moved to the top of the local scope 
  name = “Meryl Streep”; // variable assignement is left in place
  console.log(name);
}
movieStar(); // Prints “Meryl Streep”
movieStar(); // Prints “TypeError : movieStar is not a function”
var movieStar = function () {  // This is a function expression and therefore not hoisted
  var name = “Philip Seymour Hoffman”;
  console.log(name); 
}
var movieStar = function () {
  var name = “Philip Seymour Hoffman”;
  console.log(name); 
}
movieStar(); // Prints “Philipp Seymour Hoffman”
var businessStar;
function businessStar(){
  console.log(“Gary Vaynerchuck”);
}
console.log(businessStar); // Prints “function businessStar(){ console.log(“Gary Vaynerchuck”);}”
var businessStar = “Gary Vaynerchuck”;
function businessStar(){
  console.log(“Gary Vaynerchuck”);
}
console.log(businessStar); // Prints “Gary Vaynerchuck”
movieStar();
function movieStar() {
  var name = “Meryl Streep”;
  console.log(name);
}