1. Simple Functions declarations/ Function Statement
So as all of we know this is a simple ways of function declaration :
So this also called a function statement;
2. Function Expression
So what is function expressions?. As we seen above code(Simple function declaration and function call) it was a simple function statement or declaration. But now we will see how function expressions are created .
Now note that in the above image , we have declare a variable and assigned a anonymous function (function which don’t have name). But as you have notice that the method of calling the function is same as function statement.
So now the question arise , how they differ from each other?
So what is Hoisting?
So how it is relate-able to function expression and function statement?
From the below example(s) you will get to understand how hoisting works.
a. In this we called the billPaid(bill) function at line no 8.
b.In this we called the billPaid(bill) function at line no 4.
c.In this we called the billToBePaid(billAmt) function at line no 27.
d.In this we called the billToBePaid(billAmt) function at line no 23.
So function expressions are similar to variable declaration if it is not defined on the first line it will give undefined, like the below images.
So from the above contexts you had able to know about hoisting. So remember hoisting comes in two pictures.