Hint
Rest (...args) is a real Array; arguments is array-like, no arrow support, no Array methods
Rest parameters (...args) collect remaining function arguments into a real Array.
// Rest parameters β modern
function sum(first, ...rest) {
console.log(first); // 1
console.log(rest); // [2, 3, 4] β real Array!
return rest.reduce((a, b) => a + b, first);
}
sum(1, 2, 3, 4); // 10
rest.map(x => x * 2); // β
has Array methods
// arguments β legacy
function old() {
console.log(arguments); // { 0:1, 1:2, ... } β array-LIKE
console.log(arguments.map); // undefined β NOT a real Array
const arr = Array.from(arguments); // convert needed
}
// Arrow functions have NO arguments object
const arrow = () => {
console.log(arguments); // ReferenceError!
// Use rest: (...args) => { console.log(args) }
};
Key differences: