Hoisting Q2
var food = "grapes"
var foodFun = function(){
console.log("original:", food);
var food = "sushi";
console.log("new:", food);
}
foodFun();//"original: undefined"
//"new: sushi"
// this would translate to
var food = "grapes"
var foodFun = function(){
var food;
console.log("original:", food); // undefined
food = "sushi";
console.log("new:", food); // sushi
}
foodFun();
// the function will keep its scope after hoisting and the `food` var
// will be replacedThoughts
Last updated