DEV Community

 Bishnu Prasad Chowdhury
Bishnu Prasad Chowdhury

Posted on • Edited on

Javascript : types of functions

Function statements

// Allows hoisting

function test(){
   console.log("function statements");
};
test();
Enter fullscreen mode Exit fullscreen mode

Function expressions

// Doesnot allow hoisting

var a = function (){
   console.log(function expression);
};
a();
Enter fullscreen mode Exit fullscreen mode

Named function expressions

var a = function test(){
   console.log("named function expressions");
};
a();
Enter fullscreen mode Exit fullscreen mode

Function declaration

function test() {
   console.log("function declaration");
};
test();
Enter fullscreen mode Exit fullscreen mode

Anonymous function

var x = (){
};
x();
Enter fullscreen mode Exit fullscreen mode

First class function

// Ability to pass as argument and return functions as value

var x = function test(abc){
  console.log(abc);
  return function a(){
  };
};
x(function () {};);
Enter fullscreen mode Exit fullscreen mode

Arrow functions

var x = () => console.log("Arrow functions");
Enter fullscreen mode Exit fullscreen mode

Generator functions

function* square(a){
   for(let x=a;; x*=a){ 
      yield x;
      }
};

for(let z of square(2)){
    console.log(z);
}
Enter fullscreen mode Exit fullscreen mode

new Function

// Allows to convert string to function useful to handle server return codes.

var a = new Function ('a','b', 'return a+b');
console.log( sum(3,6));
Enter fullscreen mode Exit fullscreen mode

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay