Arrow Functions

Arrow Functions
πŸ‘¨β€πŸ’Ό Great work! You've learned when and how to use arrow functions.
πŸ¦‰ Key takeaways:
  1. Implicit returns work when the function body is a single expressionβ€”no braces, no return keyword needed
  2. Arrow functions are perfect for callbacks because they're concise and don't rebind this (we'll learn about this later)
  3. 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 {
	// ...
}

Please set the playground first

Loading "Arrow Functions"
Loading "Arrow Functions"