JavaScript
Iterate on possibly undefined values

by Benny Neugebauer

const paths = dialog.showOpenDialog(dialogOptions);
const importFilename = paths ? paths[0] : undefined;

if (importFilename) {
  console.log(`Importing "${importFilename}"...`);
}

let importFilename;

try {
  [importFilename] = dialog.showOpenDialog(dialogOptions);
} catch (error) {
  console.error(`Dialog error: ${error.message}`);
}

if (importFilename) {
  console.log(`Importing "${importFilename}"...`);
}