A.5. Arrow function expressions
Arrow function expressions (a.k.a. fat arrow functions) provide a shorter notation for anonymous functions and add lexical scope for the this variable. The syntax of arrow function expressions consists of arguments, the fat arrow sign (=>), and the function body. If the function body is just one expression, you don’t even need curly braces. If a single-expression function returns a value, there’s no need to write the return statement—the result is returned implicitly:
let sum = (arg1, arg2) => arg1 + arg2;
The body of a multiline arrow function expression has to be enclosed in curly braces and use the explicit return statement:
(arg1, arg2) => { // do something return someResult; }
If an arrow function doesn’t ...
Get TypeScript Quickly now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.