Is arrow function a new feature of es6?

WBOY
Release: 2022-03-30 17:53:55
Original
1719 people have browsed it

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);
Copy after login

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!

Related labels:
es6
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!