Arrow Functions in JavaScript

Arrow functions were introduced in ES6 / ECMAScript 2015 and provides a concise way to write functions in JavaScript.

Arrow Functions in JavaScript, JavaScript Arrow Function, Arrow function expressions, JavaScript: Arrow Functions for Beginners, arrow function example, arrow function typescript, arrow function in react js

Here We have provided the syntax difference between the Normal function and Arrow function.

Normal function Arrow function

Way to write arrow functions in JavaScript

  1. No Parameters function
  2. Single Parameter function
  3. Multiple Parameter function
  4. Single line No Parameter function (Implicit return)
  5. Single line Single Parameter function (Implicit return)
  6. Single line Multiple Parameters function (Implicit return)

1. No Parameters function

If you don’t have any parameters in function and you want to use the arrow function then just use ().

2. Single Parameter function

If Method contains single parameter then you can directly write the parameter without having (). You can also use () as well.

3. Multiple Parameter function

If you have a method which contains multiple parameters then you can define function like below.

4. Single line No Parameter function (Implicit return)

Arrow functions allow you to have an implicit return that means values are returned without having to use the return keyword. In other words, you can say single line function.

5. Single line Single Parameter function (Implicit return)

Same as above, if you have single parameter then you can write the function as below.

6. Single line Multiple Parameters function (Implicit return)

Let’s say if you have multiple parameters then your function should look like below.

Here is another example for you.

Thanks for reading and happy coding!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *