Get the App
SLTechnology News&Howtos  ›  Development  › 

Is the arrow function a new feature of es6?

Shulou Source: shulou.com Published: 2022-06-01 02:21:52 09月27日 Update

Editor to share with you whether the arrow function is a new function of es6, I hope you will gain something after reading this article, let's discuss it together!

The arrow function is a new feature of es6; the arrow function is a new function in es6 that allows you to define functions using the arrow "= >". It supports expressions and statement bodies relative to ordinary functions, and the arrow function has the same scope as the code around this.

This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.

Is the Arrow function a New feature of es6?

A new function has been added to the ES6 standard: Arrow Function (Arrow function), which allows you to define functions using the arrow = >.

Compared with ordinary functions, it is syntactically similar to the related functions in Java 8, supporting expressions and statement bodies.

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

1. You don't need the function keyword to create a function.

2. Omit the return keyword.

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

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

The function of arrowhead function

/ / 1. Make the expression more concise const isEven = n = > n% 2 = = 0% Const square = n = > n * n; / / 2, simplify callback function / / ordinary function writing [1line 2mag3] .map (function (x) {return x * x;}); / / arrowhead function writing [1ZO2CH3] .map (x = > x * x)

Es5 is written:

Arrow function:

After reading this article, I believe you have a certain understanding of "Arrow function is a new function of es6". If you want to know more about it, welcome to follow the industry information channel. Thank you for your reading!

Tags: Function arrowhead new function normal function key keyword writing same code article expression statement syntax support different concise function parameter name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Huawei vpn Shulou Information Redmi