JavaScript => Arrow function Operator
Arrow functions (=>) are a short way to write functions. They don't have their own this, which makes them convenient for callbacks.
Description
An arrow function is a compact function expression: (a, b) => a + b. With a single parameter the parentheses are optional, and with an expression body the result is returned automatically. A body in braces needs an explicit return, and to return an object literal directly, wrap it in parentheses: () => ({ id: 1 }).
Arrow functions don't have their own this, arguments or super; they use those of the surrounding code. That makes them ideal for callbacks inside methods, but unsuitable as object methods that need this, and they can't be used as constructors.
Arrow functions can be async, async () => { ... }, but not generators. A line break can't come between the parameters and the arrow. Because they're expressions, they're not hoisted like function declarations, so they must be defined before they're called. Their concise syntax makes them the most common choice for callbacks to methods like map(), filter() and addEventListener().
Properties
- Operator
=>- Category
- Other
- Precedence
- 2 (1 is lowest, 18 is highest)
- Associativity
- right-to-left
Syntax
(param1, param2) => expression
param => expression
(params) => { statements }Example
Browser Support
The following information will show you the current browser support for the => operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





