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.


RESETRUNFULL
<!DOCTYPE html><html><body><script>

// f();  // TypeError:{
   f(); // 'hi'
   function f() {console.log('hi');}}f(); // ReferenceError if in Strict Mode

</script></body><html>

Functions declared within another function are accessible and hoisted within the parent function only.


RESETRUNFULL
<!DOCTYPE html><html><body><script>

function f(){
   g();
   function g(){console.log('hi');}}f();  // hig();  // Reference Error

</script></body><html>