let Menu = {};
Menu.specialty = "Roasted Beet Burger with Mint Sauce";
module.exports = Menu;
let Menu = {}; creates the object that represents the module Menu. The statement contains an uppercase variable named Menu which is set equal to an empty object.
Menu.specialty is defined as a property of the Menu module. We add data to the Menu object by setting properties on that object and giving the properties a value.
"Roasted Beet Burger with Mint Sauce";is the value stored in the Menu.specialtyproperty.
module.exports = Menu; exports the Menu object as a module. module is a variable that represents the module, and exports exposes the module as an object.
module.exports exposes the current module as an object.
specialty and getSpecialty are properties on the object.
import
ES6 module syntax also introduces the import keyword for importing objects. In our order.js example, we import an object like this:
import Menu from './menu';
import keyword begins the statement.Menu here specifies the name of the variable to store the default export in.from specifies where to load the module from.'./menu' is the name of the module to load. When dealing with local files, it specifically refers to the name of the file without the extension of the file.import { specialty, isVegetarian } from './menu';
console.log(specialty);
specialty and isVegetarian are imported.