Getting Started with Arrow Functions in JavaScript


functions in javascript

Arrow function syntax gives JavaScript developers another way of writing functions. The syntax is the following:

(p1,p2, …, pn) => expression

That is, it is a comma-separated parameter list grouped by parentheses followed by a right pointing fat arrow then its function body. Below is an example of an arrow function expression:

let multiply = (a,b) => { console.log(a * b); }

They have shorter syntax than traditional function expressions. There is no function keyword. Also, when there is one expression in the function body kept to one line, the curly braces and return keyword can be omitted. For example, the following expression is valid:

let multiply = (a,b) => a * b;

References #

  1. Arrow Function Expressions - JavaScript | MDN. Accessed 21 May 2021.
  2. Arrow functions, the basics. Accessed 21 May 2021.
  3. JavaScript Arrow Functions: Fat and Concise Syntax in ES6. Accessed 21 May 2021.

Since you've made it this far, sharing this article on your favorite social media network would be highly appreciated 💖!

For feedback, please ping me on Twitter.