An arrow function is a compact JavaScript function expression, also called a lambda or fat-arrow function. It is useful when a function is needed as a value: assign it to a name, pass it to another function, or write it directly where an operation needs custom behavior. Arrow syntax keeps the focus on a function’s input and result rather than the ceremony of a traditional anonymous function. section 1.2 section 3.3
For a single expression, the expression becomes the returned value. The arrow version below does the same work as `function(num) { return Math.pow(num, 2); }`, but makes the parameter and calculation easier to scan: `num => Math.pow(num, 2)`. A multi-statement body can also be enclosed in braces. section 1.2 section 3.3
Replace a manual loop with map
An imperative loop squares each array item by managing an index and changing the array. `map` accepts a function instead, so the operation can state the transformation directly: `[0, 1, 2, 3].map(num => Math.pow(num, 2));` The arrow function receives one number and returns its square. The result is `[0, 1, 4, 9]`. Passing this small function to `map` removes loop-counter and index-handling code, making the transformation reusable as part of a larger operation. section 1.2 section 3.3
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(num => Math.pow(num, 2)); //-> [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
Browse the short callback form beside its mapped output: the arrow function supplies the calculation that `map` applies to every array element. section 1.2
Arrow functions fit naturally with first-class and higher-order functions. For example, `p => p.fullname` describes how to get a person’s name; it can be stored in `name`, supplied to `map`, or combined with filtering and reduction. The function is a value that captures a computation rather than a completed value. section 3.3 section 3.3
Use arrow functions to make small data operations more direct:
- Extract a property: `const name = p => p.fullname;`. section 3.3
- Define a predicate: `const bornIn1903 = person => person.birthYear === 1903;`. section 3.3
- Build a calculation from focused functions: `const divide = (a, b) => a / b;`. section 1.2
- Use braces when the function body needs several statements, such as sorting an array before returning it. section 1.2
Short syntax is not the only goal. Choose either arrow or regular function syntax according to readability; both express functions. In functional-style array processing, arrows are especially handy because `map`, `filter`, `reduce`, `some`, and `every` all accept functions that specify the operation’s particular behavior without rebuilding the traversal itself. section 3.3 section 3.3






