note

944Currently online
35Today's Reading
48Share Today
Multilingual display

How do I simplify functional methods using methods and methods in ES6

2018-04-24 00:00:02

In JavaScript, it is common to define functions, directly the name of the function function, which can have a return value or no return value. If there is a return value, it can be written more concisely in ES6, using the arrow function. The following example illustrates the operation as follows:

Tools/Materials
1

ES6

2

JavaScript

3

Node.js

4

HBuilder

5

Browser

6

Screenshot tool

Methods/Steps
1

The first step is to open a JavaScript file in the HBuilder tool and define a function called showInfo, as shown below:

2

In the second step, run the JavaScript directly using Node Application and see that the console prints NaN as shown below:

3

This page is based on experience

4

Step 4, run the file again and you can see that the console prints the product of two parameters, as shown below:

5

In the fifth step, since this function has a return value, remove the braces and return and replace it with an arrow, as shown below:

6

In the sixth step, save the code again and run the file, and the result is the same as in the third step, as shown below:

Matters needing attention
1

Notice how functions are condensed and called in ES6

2

Note the use of arrow functions in ES6

Recommendation