CKTIS / JavaScript
Arrow function
An arrow function is an expression that creates a function using =>. It can implicitly return an expression's result and uses this from its surrounding context rather than establishing its own this when called.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
parameter => expression
(parameters) => expression
(parameters) => { statements }
(parameters) => ({ property: value })An arrow function is an expression that creates a function using =>. Parentheses can be omitted only for one parameter that is a simple identifier: value => value * 2. No parameters, multiple parameters, a default value, destructuring, or a rest parameter require parentheses. A line break is not allowed before =>.
An expression body implicitly returns its result. A body in {} contains statements and needs return to return a value other than undefined. An implicitly returned object literal must be parenthesized: value => ({ result: value }); otherwise, {} starts a block.
An arrow function creates no bindings of its own for this, super, or new.target; references to them resolve in the enclosing lexical environment where permitted. An arrow function does not create an implicit arguments object. The name arguments follows normal lexical scoping rules: in non-strict code, the body of (arguments) => arguments refers to the arrow's own parameter, not to an enclosing binding. In the example, multiply uses the this of the run method. Do not substitute an arrow for a method that needs this to depend on the call's receiver.
An arrow function is not a constructor: calling it with new throws TypeError. In the example, multiply implicitly returns a product and wrap returns an object; the expected output is 12.
Examples
const calculator = {
factor: 3,
run() {
const multiply = value => value * this.factor;
const wrap = value => ({ result: multiply(value) });
return wrap(4).result;
}
};
console.log(calculator.run());Result
12
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.