ARROW FUNCTIONS => JAVASCRIPT

MoisesN
Jan 18, 2021
Photo by Matt Ridley on Unsplash

This is an interesting feature of Javascript that allows to shorten code, make it easier to read and simple

Lets declare the array colors first:

let colors = [‘white’, ‘red’, ‘blue’];

Here is an example of forEach function:

colors.forEach(function (color){
console.log(color)
});

Now with arrow function:

colors.forEach(color => console.log(color));

More examples to understand better:

function sum(m, n){

return m+n
}

With Arrow Function:

let sum = (m,n) => m+n;

function isPositive(num){

return num ≥=0;

};

With Arrow Function:

let isPositive = num => num ≥=0;

function randomNumber(){

return.Math.random;

};

With Arrow Function:

let randomNumber = () => Math.random;

--

--