ECMAscript 2015 also simplifies the definition of function expressions, allowing functions to be defined using the conformed form of arrows. This form simplifies the definition of functions and adds some new features. Specifically, let’s look at grammar first. The traditional way to define a function expression is through the function keyword. Now you can use the arrow function of ES2015 to define exactly the same function.

Function inc (number) {return number + 1} // equivalent to const inc = n // Return console.log(inc(100)) => n + 1; return console.log(inc(100));Copy the code

The main change to the arrow function is that it greatly simplifies writing callback functions

Const arr = [1, 2, 3, 4, 5, 6, 7] arr. Filter (function (item) {return item%2}) const arr. Filter (I => I %2)Copy the code