Array Destructuring
👨💼 Excellent! You've mastered array destructuring.
🦉 Key patterns:
- Position-based extraction:
const [first, second] = arr - Rest pattern:
const [head, ...tail] = arr - Tuple destructuring:
const [x, y, z] = coordinates - Function return destructuring:
const [min, max] = getMinMax(nums)
This pattern is foundational for React hooks:
// useState returns a tuple!
const [count, setCount] = useState(0)
// useReducer too
const [state, dispatch] = useReducer(reducer, initialState)
The rest pattern (
...) is also the foundation for the spread operator, which
you'll use extensively for immutable updates.