Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 1.7 KB

es6.md

File metadata and controls

33 lines (25 loc) · 1.7 KB

ES6

Arrow Functions

One of a programmer's favorite things to do is to write clean and concise code. Arrow Functions are a new way to write functions, given to us by the ECMAScript 6 (The software standard JavaScript is based upon) update of JavaScript.

It's a little different from regular functions, take a look:

// ES5 Function
function addNum(num1, num2) {
  return num1 + num2;
}

// Arrow Function (stored in variable)
const addNum = (num1, num2) => {
  return num1 + num2;
};

If you've done some research, you may come to the following conclusions:

  1. First of all, the Arrow Function is anonymous by design. If we want to refer to it, we should store it into a variable.
  2. Secondly, the way Arrow Functions can be written can differ (while still working the same way). Sometimes you don't need the () if there's a single parameter. Sometimes you can return a value without use for the return keyword.

Extra reading on arrow functions: