FAQ: Intermediate JavaScript Modules - module.exports II

This community-built FAQ covers the “module.exports II” exercise from the lesson “Intermediate JavaScript Modules”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise module.exports II

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

The line 1 of 2-airplane.js is unnecessary. We export an anonymous object and in that line we are creating an empty object stored in the variable Airplane. The two objects have no relation. And we can store the module object in a variable named Airplane in the 2-missionControl.js file with require() and call the properties and methods in that variable Airplane.

10 Likes

This was the exact reason for me looking into the forum today lol. Thanks!

1 Like

Same! Thanks :slight_smile:

1 Like

Same here - it’s very confusing for a beginner.

Am I correct in saying that they should have put “Menu.” in front of each of the properties in the example? Then it would make sense and you export “Menu”. Or as stated here, don’t define an object and then subsequently export an anonymous object.

Absolutely right with my thinking

I was looking for the confirmation of my doughts about the first line too. Thanks.

Thank you for posting this. I was very also very confused about this being a beginner.

it would be great if someone from Codecademy could weigh in here. We all seem to agree in this thread that line 1 is unneccessary. Why is it there?

Hi
i want to use the errow function, in by runing it its not went through, pls fix it.
thanks

You want to use an arrow function where? Please post a link to the lesson you are referring to, so we can see what you are talking about.

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

thanks

Why do you ask us to use double quotes for part 1? That does not follow convention or the former course.

6 Likes

@jbevarts I agree; I was doing it and I tried to set the value of myAirplane to ‘CloudJet’ and it was wrong and then I changed it to “CloudJet” and it worked. o.O

1 Like

I thought anonymous functions could be written func: (arr) => { …
}
Does the arrow change the scope?

I tried to wrap two separate variables in my code, say:

module.exports = {
  name:'jack',
  family: 'Pitter'
};
module.exports = function plus(a,b){console.log (a+b)};

and on the import side I always have access only to the last piece of code, I exported by this “module.exports = …” method. So just to make sure, as I understood this particular method lets us to export only one fragment of code right?

I don’t get why everybody says that the first line of code is unnecessary. Could somebody explain why?

module.exports = {
  myAirplane: "CloudJet",
  displayAirplane: function() {
    return this.myAirplane;
  } 
};

If without module.exports on the first line of 2-airplane.js, the object could not be exported to 2-missionControl.js, right?

Formerly, the instructions told you to write this:

let Airplane = {};
module.exports = {
myAirplane: “CloudJet”,
displayAirplane: function() {
return this.myAirplane;
}
};

Oops, for some reason the first line went missing…
And yes, I totally agree that it is not necessary.
Thanks for your reply!

@jbevarts I’m a complete noob, but my guess is that node exports the object in JSON, which for some reason requires double quotes.