DEV Community

Cover image for Intro - Types of functions
G U BHARATH CHANDRA
G U BHARATH CHANDRA

Posted on

Intro - Types of functions

A Function in javascript is a collection of instructions that run when the function is invoked.

A normal function declaration in javascript is as declared as below:

function square(n){
  return n*n;
}

// Then invoke it as :

console.log(square(5)); // 25
Enter fullscreen mode Exit fullscreen mode

While the above is understood, functions can also be declared as Function expression:

const square = function(n){
  return n*n;
}

// Then invoke it as :

console.log(square(5)); // 25
Enter fullscreen mode Exit fullscreen mode

There are many types of functions which I will cover in this 6 part series.

Different types of functions:

  • Function declaration and Anonymous functions
  • Arrow functions
  • Methods
  • Immediately invoked function expressions
  • Callback functions
  • Generator functions

Stay tuned for further posts.

Top comments (0)