โ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 
- see๏ผ โ๏ธ TypeError โฉ 'xxx' is not a functionโ๏ธ 
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?