function fn(...rest) {
    console.log(rest); // rest arguments received as an array
}

fn(1, 2, 3); // Output: [1, 2, 3]
fn(1, 2, 3, 4); // Output: [1, 2, 3, 4]
fn(1, 2, 3, 4, 5); // Output: [1, 2, 3, 4, 5]
const expressionFn = function (...rest) {
    console.log(rest); // rest arguments received as an array
}

expressionFn(1, 2, 3); // Output:  [1, 2, 3]
expressionFn(1, 2, 3, 4); // Output:  [1, 2, 3, 4]
expressionFn(1, 2, 3, 4, 5); // Output:  [1, 2, 3, 4, 5]
const arrowFn = (...rest) => {
    console.log(rest); // rest arguments received as an array
}

arrowFn(1, 2, 3); // Output:  [1, 2, 3]
arrowFn(1, 2, 3, 4); // Output:  [1, 2, 3, 4]
arrowFn(1, 2, 3, 4, 5); // Output:  [1, 2, 3, 4, 5]
// When there are fixed parameters
function functionName(param1, [param2,] ...restParams) {
    // You can use restParams as an array inside the function body
}

// When there are no fixed parameters
function functionName(...restParams) {
    // You can use restParams as an array inside the function body
}
function myFun(a, b, ...manyMoreArgs) {
    console.log("a:", a);
    console.log("b:", b);
    console.log("Rest parameter manyMoreArgs:", manyMoreArgs);
}

myFun("apple", "banana", "cherry", "date", "elderberry", "fig");

// Output:
// a: apple
// b: banana
// Rest parameter manyMoreArgs: [ 'cherry', 'date', 'elderberry', 'fig' ]
// Incorrect: more than one rest parameter
function wrong1(...one, ...wrong) {} // Error
// Incorrect: rest parameter not last
function wrong2(...wrong, arg2, arg3) {} // Error
function exampleFunction(a, b, ...restParams) {
    // function body
}

console.log(exampleFunction.length); // Output: 2
console.log("Hello", "World", "!");
// Output: "Hello World !"
function sum(...numbers) {
    let total = 0;
    
    for (let number of numbers) {
        total += number;
    }
    
    return total;
}

console.log(sum(1, 2, 3, 4, 5)); // Output: 15