📎 Webclip
Extract Functions Arguments using Destructure in JavaScript
The page explains a simple pattern for handling function inputs in JavaScript: collect the passed values with a rest parameter, then unpack them with array destructuring. It also separates the idea of a parameter from the actual argument value and contrasts both with the built-in arguments object.
Reading notes#
- Use
...argsto collect passed values into a real array, then assign them with[egg, cheese] = args - The
argumentsobject exists in every non-arrow function, but it is array-like rather than an array - A parameter is the variable in the function declaration, while an argument is the value passed at call time
- The page recommends rest parameters over
argumentsbecause they are explicit and return a real array - AirBnB style guidance says not to name a parameter
arguments - The page shows that defaults can be set directly in the header with
...[egg = '', cheese = ''] - It also shows that rest parameters can be destructured directly as
...[egg, cheese]
