Arrow Functions

๐Ÿ‘จโ€๐Ÿ’ผ Nice! Arrow functions are concise and very common in modern JavaScript.
๐Ÿฆ‰ Arrow function shortcuts:
// Single parameter - parentheses optional
const double = (n) => n * 2
const double = (n) => n * 2 // Same thing!

// No parameters - parentheses required
const sayHi = () => 'Hi!'

// Multiple lines - braces and return required
const calculate = (a, b) => {
	const sum = a + b
	const product = a * b
	return { sum, product }
}
Arrow functions have a subtle difference with this binding, which becomes important later. For now, just know that both syntaxes work for most cases.
Use arrow functions for:
  • Short utility functions
  • Callbacks (functions passed to other functions)
  • Array methods like map, filter, forEach

Please set the playground first

Loading "Arrow Functions"
Loading "Arrow Functions"