DEV Community

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

Posted on

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)