INTERMEDIATE JAVASCRIPT MODULES : module.exports


#1

Hi Guys,

I’m working on this exercise.

on this page it gives this code example for the file menu.js:

let Menu = {};
Menu.specialty = "Roasted Beet Burger with Mint Sauce";

module.exports = Menu;

Then down below it says that:

_1. let Menu = {}; creates the object that represents the module Menu . _
2. 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.

Okay, hold it right there. I get confused on 2. above: If Menu.specialty is defined as a property of the Menu module, why isn’t it written like this:

let Menu = {
  Menu.specialty = "Roasted Beet Burger with Mint Sauce";
};

module.exports = Menu;

Notice above that I put Menu.specialty = “Roasted Beet Burger with Mint Sauce”; inside the {} of Menu. In their example, it just seems to go against the convention I’ve been learning.


#2

Inside the object, we only use the property name and object syntax.

let Menu = {
    specialty: "Roasted Beet Burger with Mint Sauce"
}

#3

Okay, thank you. I made that change and it was accepted but, so isn’t the other way. :face_with_raised_eyebrow: It seems odd that the example in the tutorial narrative also shows the empty object:

let Menu = {};
Menu.specialty = "Roasted Beet Burger with Mint Sauce";

module.exports = Menu;

I think i’m not understanding something otherwise codecademy would have written like this:

let Menu = {
  Menu.specialty: "Roasted Beet Burger with Mint Sauce"
};
module.exports = Menu;

since they didn’t show it as displayed above, i’m left assuming that I need to understand that claiming Menu.specialty is a property of the empty object is the correct way to write it.

let Menu = {};
Menu.specialty = "Roasted Beet Burger with Mint Sauce";

module.exports = Menu;

That just seems so wrong but, whatever.


#4

That is how we make assignments outside of the object.

We do not address the object we are inside of.

let Menu = {
    specialty: "Roasted Beet Burger with Mint Sauce"
};

#5

Thank you Roy. I appreciate your insight.