function fn(...rest) {
    console.log(rest); // 배열로 전달 받은 rest
}

fn(1, 2, 3); // 출력: [1, 2, 3]
const expression_fn = function (...rest) {
    console.log(rest); // 배열로 전달 받은 rest
}

expression_fn(1, 2, 3); // 출력:  [1, 2, 3]
const arrow_fn = (...rest) => {
    console.log(rest); // 배열로 전달 받은 rest
}

arrow_fn(1, 2, 3); // 출력:  [1, 2, 3]
function functionName(param1, param2, ...restParams) {
    // 함수 본문에서 restParams를 배열로 사용할 수 있습니다.
}
function myFun(a, b, ...manyMoreArgs) {
    console.log("a:", a);
    console.log("b:", b);
    console.log("Rest 파라미터 manyMoreArgs:", manyMoreArgs);
}

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

// 출력:
// "a: apple"
// "b: banana"
// "Rest 파라미터 manyMoreArgs:" [ 'cherry', 'date', 'elderberry', 'fig' ]
function wrong1(...one, ...wrong) {} // 에러
function wrong2(...wrong, arg2, arg3) {} // 에러
function exampleFunction(a, b, ...restParams) {
    // 함수 본문
}

console.log(exampleFunction.length); // 출력: 2
console.log("Hello", "World", "!");
// 출력: "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)); // 출력: 15
Rest 파라미터의 브라우저 호환성
함수
데스크탑 Chrome
Chrome
데스크탑데스크탑 Edge
Edge
데스크탑 Firefox
Firefox
Safari
Safari
...restParams 47 12 15 10

caniuse.com에서 더 자세한 정보를 확인해 보세요.