Bada
Bada's Coding

Follow

Bada's Coding

Follow

Keys in Destructured Parameters Can Have Default Parameters

Bada's photo
Bada
·Jan 3, 2023·

1 min read

Below is an example.

const obj1 = {};
const obj2 = { k: 2 };

function fn({ k = 1 }) {
  console.log(k);
}

fn(obj1); // 1
fn(obj2); // 2
 
Share this