[Javascript] Hositing
First, memory is set aside for all necessary variables and declared functions.
Function expression never got hosited in Javascirpt. Therefore, you can see var x = undefined;
Examples:
Defined function will move top in front of return statment.
Example 3: Function expressions are never hoisted! They are treated as assignments.
Example 4: Picture below the noSeats and seatsAvail functions will never get chances to show off. Because when call noSeats() inside if statment, it is undefined!!. Javascirpt return error!
So How to fix the problem?
One: Move the function expressions to the top:
Two: Using decared function instead.