🔰function hoisting
identifier hoisted at top of scope, value initialized to a function value (instantly).
JS ⟩ scope ⟩ hoisting ⟩ function hoisting
with a function declaration:
identifier: hoisted to the top of its scope.
referencing a function in block (FiB) outside block
sloppy mode: ✅ hoisted / initialized to undefined (outside block)
strict mode: ⛔ ReferenceError (invisible outside block)❗
related topics
are processed before code runs (at compile-time) so it seems that they are "hoisted" to the top of their scope.
in the same scope, function hoisting has higher priority over variable hoisting. ( 👉 function hoisting first❗️❗)
replit:function hoisting
// function declarations can be called from the start
greeting(); // Hello!
// ⭐️ function hoisting
// ------------------------------------------------------
// • applies to "function declarations" only.
// • identifier: (function name) hoisted to top of scope.
// • value : initialized (to a function value).
// ------------------------------------------------------
function greeting() {
console.log("Hello!");
}Last updated
Was this helpful?