Need help understanding the relationship

Hello, I’m struggling a bit with the module exports class.

In lesson 2 The example code provided for menu.js:

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

module.exports = Menu;

Above, I understand that let Menu = {} and Menu.specialty are connected somehow because of the key word ‘Menu’. I think this is confirmed in the description below. Also, Lesson 3 seemed to reinforce this as well.

Along comes lesson 4 where let Menu = {}; created at the top in menu.js is not referenced below in the module.exports. See below.

// part A below
let Menu = {};

// part B below 
module.exports = {
  specialty: "Roasted Beet Burger with Mint Sauce",
  getSpecialty: function() {
    return this.specialty;
  } 
};

how is part A associated with part B? They are not in the same code block.

This has me perplexed. What am I not understanding?

Thank you

2 Likes

Is it?

Then, it isn’t.


That’s no keyword, it’s a variable name.

I believe you should know what object.attribute does

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects

1 Like

Thank you again. sorry i miss used the word ‘key’. I’ll be more careful. I reviewed that page on Objects and yes, i’m pretty familiar with them for a newbie. Constructors, classes I understand.

What confused me in lesson 4 is that in the file 2-airplane.js Parts A and B (defined above) are not associated with each other but, then in the file 2-missionControl.js we see console.log(Airplane.displayAirplane()); which confused me because I saw the word ‘Airplane’. Now that I look at it again, it is really referring to Part B in 2-airplane.js and has nothing to do with Part A. In fact, I removed Part A let Airplane = {}; and it still worked fine.

Hopefully, i’m not still confused.

1 Like

You’re right to be confused about that. If you look at the example in the instructions here

https://www.codecademy.com/courses/introduction-to-javascript/lessons/modules/exercises/module-exports

They do end up exporting that object.
The exercise author(s) must have changed their mind and didn’t clean it up properly.

1 Like