MENU
Scoping and Hoisting
Assuming Strict Mode(II) and anonymous functions are not used, scope-wise, a function declaration is identical to a 'var' variable declaration.
Functions declared within a local block are accessible outside the parent function but hoisted within the block only.
// f(); // TypeError
{
f();
function f() {
console.log('hi');
}
}
f();'hi'
ReferenceError if in Strict Mode
Functions declared within another function are accessible and hoisted within the parent function only.
function f() {
g();
function g() {
console.log('hi');
}
}
f();
g();hi
Reference Error