Arrow function expressions - JavaScript | MDN

developer.mozilla.org

Tin mới

HTML: Markup language

See all HTML references

Date & time formats

See all HTML guides

CSS: Styling language

See all CSS references

See all CSS guides

Centering an element

JavaScript: Scripting language

Standard built-in objects

Expressions & operators

Statements & declarations

See all JavaScript references

Control flow & error handing

Loops and iteration

Working with objects

See all JavaScript guides

Web APIs: Programming interfaces

Service worker API

Using the Web animation API

Using the Fetch API

Working with the History API

Using the Web speech API

All web technology

Progressive web apps

Learn web development

Getting started modules

Structuring content with HTML module

CSS styling basics module

Dynamic scripting with JavaScript module

Border-image generator

Border-radius generator

Box-shadow generator

Color format converter

function expression

An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate limitations in usage:

default parameters

Rest parameters, default parameters, and destructuring within params are supported, and always require parentheses:

Object.defineProperty()

Arrow function expressions should only be used for non-method functions because they do not have their own this. Let's see what happens when we try to use them as methods:

Cannot be used as methods

Arrow function expressions should only be used for non-method functions because they do not have their own this. Let's see what happens when we try to use them as methods:

Cannot be used as methods

Arrow function expressions should only be used for non-method functions because they do not have their own this. Let's see what happens when we try to use them as methods:

Cannot be used as methods

Arrow function expressions should only be used for non-method functions because they do not have their own this. Let's see what happens when we try to use them as methods:

Cannot be used as methods

Arrow function expressions should only be used for non-method functions because they do not have their own this. Let's see what happens when we try to use them as methods:

Cannot be used as methods

Arrow function expressions should only be used for non-method functions because they do not have their own this. Let's see what happens when we try to use them as methods:

Cannot be used as methods

Arrow function expressions should only be used for non-method functions because they do not have their own this. Let's see what happens when we try to use them as methods:

Cannot be used as methods

Arrow function expressions should only be used for non-method functions because they do not have their own this. Let's see what happens when we try to use them as methods:

No binding of arguments

Arrow functions do not have their own arguments object. Thus, in this example, arguments is a reference to the arguments of the enclosing scope:

No binding of arguments

Arrow functions do not have their own arguments object. Thus, in this example, arguments is a reference to the arguments of the enclosing scope:

Cannot be used as constructors

Arrow functions cannot be used as constructors and will throw an error when called with new. They also do not have a prototype property.

Cannot be used as constructors

Arrow functions cannot be used as constructors and will throw an error when called with new. They also do not have a prototype property.

Cannot be used as generators

The yield keyword cannot be used in an arrow function's body (except when used within generator functions further nested within the arrow function). As a consequence, arrow functions cannot be used as generators.

operator precedence

Although the arrow in an arrow function is not an operator, arrow functions have special parsing rules that interact differently with operator precedence compared to regular functions.