๐Ÿ”ธrest parameters as object

๐Ÿšง under construction

JS โŸฉ object โŸฉ function โŸฉ parameter โŸฉ rest parameters as object

๐Ÿ’พ ็จ‹ๅผ๏ผšreplit

const { log } = console;

function f({        // parameter destructuring
    hi = 0,         // default parameter
    
    ...opts         // rest params as an object โญ๏ธ
    
} = {})             // default parameter
{
    log(hi);
    log(opts);
}

// test run
f();                        // 0, {}
f({ x: 1, y: 2, hi: 3 });   // 3, { x: 1, y: 2 }

Last updated

Was this helpful?