Arrow Functions
Arrow Functions
π¨βπΌ Great work! You've learned when and how to use arrow functions.
π¦ Key takeaways:
- Implicit returns work when the function body is a single expressionβno
braces, no
returnkeyword needed - Arrow functions are perfect for callbacks because they're concise and
don't rebind
this(we'll learn aboutthislater) - Function declarations are still best for top-level named functions because of hoisting and clearer stack traces
// Use arrow functions for callbacks
function applyToNumber(
value: number,
transform: (n: number) => number,
): number {
return transform(value)
}
const result = applyToNumber(5, (n) => n + 1)
// Use function declarations for top-level functions
function processOrder(order: Order): Receipt {
// ...
}


