Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre ES6 Arrow Functions | Getting Started: ES6
Introduction to React

book
ES6 Arrow Functions

Arrow functions are a new addition to JavaScript that let us create inline functions without using the function and return keywords. They are simply a shorter syntax version of the normal JavaScript functions. JavaScript function:

let myFunc = function () {
return 1 + 6;
}
console.log(myFunc());
1234
let myFunc = function () { return 1 + 6; } console.log(myFunc());
copy

ES6 function:

js
let myFunc = () => {
return 1 + 6;
}

If the function has only one statement and returns a value, then we can remove the braces and the return keyword, hence the resultant code will be:

js
let myFunc = () => 1 + 6;

We can also pass arguments in the ES6 inline functions, using the syntax:

let myFunc = (a, b) => a + b
console.log(myFunc(5, 4));
12
let myFunc = (a, b) => a + b console.log(myFunc(5, 4));
copy

Task

Create an inline function named threeProduct that takes in three numbers / arguments namely a, b, c, and returns the product of those numbers. Call the function inside a console.log function and pass 1, 2 and 9 as arguments.

question-icon

Fill in the gaps.

let threeProduct =
_ _ _
_ _ _
_ _ _
;
console.log(threeProduct
_ _ _
);
18

Click or drag`n`drop items and fill in the blanks

dots
(1, 2, 9)
dots
(a, b, c)
dots
a*b*c
dots
=>

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 4

Demandez à l'IA

expand
ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

some-alt