DEV Community

Cover image for JavaScript Arrow Functions ( easy tutorial )
Roopam Gupta
Roopam Gupta

Posted on

1

JavaScript Arrow Functions ( easy tutorial )

Before ES6, Functions were written as :

greeting = function(){
      return "This is webdevprojekts!";
}
Enter fullscreen mode Exit fullscreen mode

With the introduction of Arrow Functions in ES6 :

greeting = () => {
      return "This is webdevprojekts!";
}
Enter fullscreen mode Exit fullscreen mode

Arrow Functions return value by default, thus it gets more shorter :

greeting = () => "This is webdevprojekts!";
Enter fullscreen mode Exit fullscreen mode

Arrow Functions with parameter :

if you have parameters, you pass them inside the parantheses :

greeting = (name) => "This is webdevprojekts!" + name;
Enter fullscreen mode Exit fullscreen mode

Arrow Functions with single parameter :

if you only have one parameter, you can skip the parantheses as well :

greeting = name => "This is webdevprojekts!" + name;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

nextjs tutorial video

📺 Youtube Tutorial Series

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

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

Okay