- Passed as value
- Returned as value
So a function statement is
This can be also written as below. Here we are assigning function as expression to a variable.
Function statement are always hoisted to the scope it is defined. So you do not need to define a function before using it. Consider following example,
In above function statement, we are using function before it is defined. You will get expected result.
Now let us make function as expression,
Above lines of code will throw you exception that funct1() is undefined. So function as expression does not get hoist to its scope.
You will get following output,
If you change return of function to 0 then if statement would not get executed,
You can assign function as Object property. This can be done as following,