DEV Community

Discussion on: Put Down the Destructuring Hammer

yoursunny profile image
Junxiao Shi • Edited on

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

async function resolve({
  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