5 Rules of Arrow Functions

Arrow functions are an ES6 Javascript version of writing functions.

  1. They are always anonymous functions. In example 1, you will be able to convert it into an arrow function. In example 2, you can convert to an arrow function as well, but you would not be able to call it anyName.

2. To convert an ES5 function into an arrow function, you would take out the word function and replace it with an arrow ‘=>’

3. Curly brackets and the word ‘return’ are not necessary if you’re returning one expression.

4. When there is only one parameter, parenthesis () are optional.

5. If you’re returning an object, you must wrap it with ().

And that’s a wrap.