Map destructuring

by Artem

JavaScript

function foo(cb) {
  cb([null, {name: 'Illuxa'}]);
}

foo(([err, data]) => {
  if (err) {
    throw new Error(err);
  }
  console.log(data);
});

function bar() {
  return [null, 'Hello, world!'];
}

let [err, data] = bar();
if (!err) {
  console.log(data);
}