" to be used to define functions. Compared with ordinary functions, it supports expressions and statement bodies, and the arrow function has the same relationship with the code around this Same scope."/> " to be used to define functions. Compared with ordinary functions, it supports expressions and statement bodies, and the arrow function has the same relationship with the code around this Same scope.">

Home  >  Article  >  Web Front-end  >  Is arrow function a new feature of es6?

Is arrow function a new feature of es6?

WBOY
WBOYOriginal
2022-03-30 17:53:551712browse

The arrow function is a new function of es6; the arrow function is a new function in es6, which allows the use of arrow "=>" to define functions. Compared with ordinary functions, it supports expressions and statement bodies, and arrows Functions have the same scope as the code surrounding this.

Is arrow function a new feature of es6?

The operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.

Is the arrow function a new feature of es6?

The ES6 standard adds a new function: Arrow Function, which allows the use of arrow => to define functions.

Compared with ordinary functions, it is similar in syntax to C# and related functions in Java 8, supporting expressions and statement bodies.

Unlike ordinary functions, arrow functions have the same scope as the code around this. Arrow functions have the following characteristics:

  • #1. The function keyword is not required to create a function.

  • 2. Omit the return keyword.

  • 3. This always points to the this value in the scope where the function is declared (that is, the arrow function does not have its own this at all, but refers to the outer this).

Use ES6 arrow function syntax to define a function, delete the "function" keyword and function name of the original function, and use "=>" to connect the parameter list and function body.

The role of arrow function

// 1、使表达更加简洁
const isEven = n => n % 2 === 0;
const square = n => n * n;
 
// 2、简化回调函数
// 普通函数写法
[1,2,3].map(function (x) {
  return x * x;
});
 
// 箭头函数写法
[1,2,3].map(x => x * x);

es5 writing method:

Is arrow function a new feature of es6?

##Arrow function:

Is arrow function a new feature of es6?

[Related recommendations:

javascript video tutorial, web front-end]

The above is the detailed content of Is arrow function a new feature of es6?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn