DEV Community

Discussion on: Put Down the Destructuring Hammer

Collapse
 
yoursunny profile image
Junxiao Shi • Edited

I find destruction handy for supplying a default value to an optional field.

async function resolve({
  hostname,
  type = "A",
}) {
  return doResolve(hostname, type);
}

async function resolve(opts) {
  return doResolve(opts.hostname, opts.type ?? "A");
  // could be worse if ?? is unavailable
}
Enter fullscreen mode Exit fullscreen mode