← Back to the exercise

Modules: import and export

The answer to the exercise in Modules: import and export.

formatTitle was declared in /show.js but never exported, so it stayed private to that file and helpers.formatTitle was undefined. One export keyword puts it on the module's public surface, and /index.js takes the first branch.

import * as helpers from "./show.js";

const show = { title: "Severance", year: 2022, rating: 8.7 };

if (typeof helpers.formatTitle === "function") {
  console.log("title:", helpers.formatTitle(show));
} else {
  console.log("title: formatTitle is not exported yet.");
}

console.log("good?:", helpers.isGood(show));