Yes this is for default export and named exports. But the one Im confused about is Node’s module.export and require() that they’ve used in the lesson where they export the checkInventory function and wrap around the curly braces around the variable name, both when they export the function and when they import it.
BUT, I took a closer look at my notes, and the Codecademy lesson about modules, and saw that you CAN use the curly braces, when using Node’s module.exports, but that is when you want to export several different data, just like with named exports. BUT in the lesson we only export the checkInventory function, so what’s the point of the braces if there’s no other data we want to export?
When it comes to importing with Node’s require(), I took a look at my notes and the Codecademy lesson about modules, and I see no curly braces around the name of the module we are importing, no matter if the module we exported with Node’s module.exports consist of a single type of data, or several different data…so why do they use the curly braces around checkInventory when importing it, when nowhere in the Codecademy lesson about modules, do they use curly braces when importing with require()?
If you you look at part 2(module.exports), 3(require()) and 4(module.exports II) in lesson 11(Intermediate JacaScript Modules), you’ll see what I mean.
You can even see in the example of part 4(module.exports II) of the lesson, how they export the different data, with the curly braces, which is fine, but when they import the data, you can clearly see that there are no curly braces around the Menu module
module.exports II
We can also wrap any collection of data and functions in an object, and export the object using module.exports
. In menu.js , we could write:
module.exports = { specialty: “Roasted Beet Burger with Mint Sauce”, getSpecialty: function() { return this.specialty; } };
In the above code, notice:
-
module.exports
exposes the current module as an object.
-
specialty
and getSpecialty
are properties on the object.
Then in order.js , we write:
const Menu = require(’./menu.js’); console.log(Menu.getSpecialty());
Here we can still access the behavior in the Menu
module.
BTW, in the name of this topic I ment to write 6/12 and not 6/11. 11 is the Modules lesson, and 6/12 is the Promises lesson that gets me confused with the curly braces 