Functions :
- Will calling the function if we forget to place the parentheses, then we are getting the function definition only, but not the function output.
- A set of statements that performs a task or calculates a value.
- Defining a function does not execute it. Defining it names the function and specifies what to do when the function is called.
- Calling the function actually performs the specified actions with the indicated parameters.
Function statement :
- Declaring a function is called a function statement.
- It is also called a function declaration.
Example :
function sum(){
console.log( " function statement");
}
Function Expression :
- Assigning a function to a variable.
- The function acts as a value.
- Function called through variable name only, otherwise gives an error
Example:
var add= function (num , num2){
return num+ num2;
}
add(10,25); // function called through variable name
Difference between statement and expression :
Hoisting applies to the function statement.
Hoisting is not applicable for a function expression.