DEV Community

A K I L A N
A K I L A N

Posted on

Types of function

Expression Function

  • Function expression is stored in a variable
const multiply = function(a, b) {
  return a * b;
};
Enter fullscreen mode Exit fullscreen mode
  • the variable can be used as a function

  • function expression are used to create anonymous functions.

  • A expresion function can be assigned to a varaiable the passed a arrugument to another function and returned from function

  • In JavaScript, function declarations and function expression refer to different ways of defining functions, there are different in the syntax but both the works are same .

Hosting

  • function decleration can be called top of the function

  • function expression can be called after function decleration.

  • use function decleration in general - purpose function.

  • use function expression to assign a variable in another function and for callback .

*Arrow function *

  • Arrow function are shorten of expression function
const add = (a, b) => {
  return a + b;
};
Enter fullscreen mode Exit fullscreen mode
  • arrow function uses the arrow symbole

  • This arrow function does the same thing as a regular function expression.

  • Arrow functions are not hoisted

  • Parentheses are required for zero or multiple parameters.

Top comments (0)