❗function expression not hoisted
JS ⟩ value ⟩ function ⟩ expression ⟩ not hoisted
a function expression is never hoisted by itself❗
👉 compare: function hoisting, var hoisting.
replit:function expr not hoisted
const { log } = console;
// ⭐️ var hoisting
// ----------------
// • identifier: IS hoisted❗
// • value : initialized to `undefined`❗
log(greeting, typeof greeting); // undefined, 'undefined'
// ⭐️ identifier `greeting`:
// • can be referenced now❗ (not a compile-time ReferenceError)
// • but can't be called (not a "function") yet❗(runtime ⛔ TypeError)
greeting(); // ⛔ TypeError: 'greeting' is not a function
// ⭐️ the following is a "var declaration"
// ⭐️ "var declaration" is related to "var hoisting"
// ------------------------------------------------------
// • identifier: hoisted to top of scope❗
// • value : initialized to `undefined`❗
// ------------------------------------------------------
// ⭐️ "var declaration"
//
// ╭─ id ─╮ ╭── value ──╮ (`value` is a function expression)
var greeting = function() {
console.log("Hello!");
};
Last updated
Was this helpful?