Declaring a function

Declaring Function 1 Declaring Function 2 Declaring Function 3 Declaring Function 4 Declaring Function 5 Declaring Function 6 Declaring Function 7 Declaring Function 8

Hoisting is a JavaScript technique which moves variables and function declarations to the top of their scope before code execution begins. Within a scope no matter where functions or variables are declared, they're moved to the top of their scope.
Note: that hoisting only moves the declaration while assignments are left in place.

Also note that it doesn't work when you assign functions like variables.
Note that the function declaration was after it was called but was still called. This was possible due to function hoisting.

How a function is in memory

Functions in memory Declaring Function 9 Declaring Function 10 Declaring Function 11 Hoisting Scope

It is however important to remember that in the background, JavaScript is religiously declaring then initializing our variables.
As we mentioned before, all variable and function declarations are hoisted to the top of their scope. I should also add that variable declarations are processed before any code is executed.
However, in contrast, undeclared variables do not exist until code assigning them is executed.
Therefore, assigning a value to an undeclared variable implicitly creates it as a global variable when the assignment is executed. This means that, all undeclared variables are global variables.