Reid  Rohan

Reid Rohan


How to Use Arrow Functions in JavaScript

The arrow function is a cool addition to the ES6 syntax of writing JavaScript, introduced in 2015, arrow functions are a shorter way to write functions in JavaScript. Using an arrow function strips away the need to use the function keyword when initializing a function. The code snippet below is an example of an arrow function in comparison with the regular ES5 function. It’s worth mentioning that arrow functions are completely anonymous (you cannot name them as you would with the regular ES5 syntax).

// cool new ES6 syntax

const greet = name => {
  return 'Hello ' + name;
greet('Joe'); // Hello Joe

// old ES5 syntax

function greet(name) {
  return 'Hello ' + name;
greet('Janet'); // Hello Janet

#javascript #es6 #functions

How to Use Arrow Functions in JavaScript