Rest Parameter (...) : The rest parameter in JavaScript (introduced in ES6) allows a function to accept multiple arguments and collect them into a single array.
Syntax
function functionName(...args) {
// args is an array
}function sum(...numbers) {
console.log(numbers);
}
sum(1, 2, 3, 4);Output: [1, 2, 3, 4]
Rest parameter must be the last parameter in a function.
function test(...numbers, a) {
}
Invalid ❌
No comments:
Post a Comment