All about JavaScript Function

  • Function is a store of steps that you take to perform certain action.

Parameter and Argument

Parameter

  • Parameter is defined when defining a function .
  • Parameter are the placeholder.

Argument

  • The value that pass when you calling a function.
  • Argument are the real value.

Default Parameter

  • The default parameter is a way to set default values for function parameters a value is no passed in
function multiply(a, b = 1) {
  return a * b;
}

console.log(multiply(5, 2));
// expected output: 10

console.log(multiply(5));
// expected output: 5

Different Types of function

Function Declaration

function add(numA, numB){
return numA + numB;
}

Function Expression

  • It can stored in a variable.
const addNumber=function add(numA, numB){
return numA + numB;
}

Anonymous Function Expression

  • Do not need function names
const addNumber=function (numA, numB){
return numA + numB;
}

Arrow Function Expression

  • No need to write function key;
const addNumber=(numA, numB)=>{
return numA + numB;
}
const addNumber=(numA, numB)=>
 numA + numB;