Home  >  Article  >  Web Front-end  >  When is the Arguments Object Available in ES6 Arrow Functions?

When is the Arguments Object Available in ES6 Arrow Functions?

Susan Sarandon
Susan SarandonOriginal
2024-10-18 15:58:02606browse

When is the Arguments Object Available in ES6 Arrow Functions?

Arguments Object in ES6 Arrow Functions: Official Documentation

Arrow functions have swiftly captured the attention of developers with their concise syntax. However, one aspect that has raised questions is the availability of the arguments object within them.

According to the official documentation from TC39, the governing body for JavaScript standardization, arrow functions do not create their own arguments object. Unlike regular functions, arrow functions inherit the arguments object from their parent scope.

This behavior is evident in the following example where an arrow function is invoked with three arguments:

<code class="js">(() => console.log(arguments))(1, 2, 3);</code>

In environments like Chrome, Firefox, and Node.js, this code will log "1,2,3". However, Babel and other bundlers raise an error indicating that arguments is not defined.

This discrepancy arises because some environments allow arrow functions to access the arguments object of their parent scope, while others implement the strict interpretation of the ES6 specification, which prohibits arrow functions from having their own arguments object.

In summary, the official documentation from TC39 (ES6 specification) clearly states that arrow functions do not possess their own arguments object. The observed behavior in certain environments where arrow functions can access the parent scope's arguments is non-standard and may result in unexpected outcomes.

The above is the detailed content of When is the Arguments Object Available in ES6 Arrow Functions?. 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