DEV Community

Edward Mendoza
Edward Mendoza

Posted on

Arrow functions

This is my third post, and i will talk about arrow functions, which is a new way to create functions.

Arrow Functions

In this past weeks, we have been working with javascript ES6, and moved into react, and one of the main things that i learn was about arrow functions, im going to describe which are one of the main benefits that i consider it.

Benefits

By using arrow functions, it allow us to manage the this context a bit easier, since is bind by default and the other one i would say is short sintaxis which at the same time makes easier to read/create them.

Examples

function multiply (x,y) {
  return x * y;
}

Let's consider the above example, is the regular way to create a function now let's create the same function but as an arrow function.

let add = (x,y) => {
  return x + y;
}

if no arguments are being pass, we can write the function as follows

let saySomething = () => {}

Even to simplify a bit more, we can even return on the same line of code without {}

let add = ( x, y) => x + y

So this is arrow functions in a brief description

Discussion (0)