JavaScript › Destructuring, Spread & Rest
Why must the rest element be the LAST element in a destructuring pattern?
AdvancedAnswer
Rest collects 'everything remaining' after the named elements are extracted, so its position only makes sense as the final element — putting it earlier would make the remaining count ambiguous, and JavaScript throws a SyntaxError.
const [first, ...rest] = [1, 2, 3, 4]; // valid: rest = [2,3,4]
// const [...rest, last] = [1,2,3]; // SyntaxErrorReal-world example Splitting an array into its head and tail for recursive-style processing.