Performance: Rest parameters
Rest parameters affect JavaScript function call performance and bundle size, impacting initial load and interaction responsiveness.
function sum(...args) { return args.reduce((a, b) => a + b, 0); }
function sum() { var args = Array.prototype.slice.call(arguments); return args.reduce((a, b) => a + b, 0); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using arguments object with slice | 0 | 0 | 0 | [X] Bad |
| Using rest parameters | 0 | 0 | 0 | [OK] Good |
...props inside a component's export let statement do?export let ...propsprops, allowing flexible access.props. -> Option C... before the variable name in export let.export let ...restProps; correctly uses export let ...restProps;. Options A, C, and D misuse assignment or spread placement.export let ...name; [OK] <script>
export let name;
export let ...restProps;
</script>
<h1>Hello {name}!</h1>
<pre>{JSON.stringify(restProps)}</pre>
<MyComponent name="Anna" age={30} city="NY" /><pre> tag?name is separate; restProps collects all other props like age and city.age and city and their values.<script> export let ...props; console.log(props); </script>
<button> element. Which code correctly uses rest parameters to achieve this?export let to collect arbitrary extra HTML attributes.export let attrs = {}; and spreading {...attrs} on the button is the correct way to accept and apply extra attributes.Pass the test and this pattern moves unknown