May 2019
Intermediate to advanced
316 pages
7h 13m
English
The traditional way of defining a function in JavaScript is by using a function keyword. The following function gets one argument and just returns the argument value:
function hello(greeting) { return greeting;}
But when we use the ES6 arrow function, the function looks as follows:
const hello = greeting => { greeting }// function callhello('Hello World'); // returns Hello World
As we can see, by using the arrow function, we have made the declaration of the same function more compact.
When you have more than one argument, you have to wrap the arguments in parentheses and separate the arguments with a comma to use the arrow function effectively. For example, the following function gets two parameters and returns the sum of ...
Read now
Unlock full access