JS: Function Name Hoisting
Function Declaration Hoist Name and Value
- Function declaration implicitly move (aka hoist) the function name and definition to the top.
- Function expression assigned to variable only hoist the name, not the definition. (in Deno, neither.)
Compare:
console.log(f() === 3); function f() { return 3; }
// deno // error: Uncaught ReferenceError: Cannot access 'g' before initialization g(); const g = function () { return 3; };