Properties defined outside the object


#1

Regarding: https://www.codecademy.com/courses/intermediate-javascript-modules/lessons/modules/exercises/export-default?action=lesson_resume&course_redirect=introduction-to-javascript

Why should I opt to define object properties outside of the object, like this:

let Airplane = {};

export default Airplane;

Airplane.availableAirplanes =[
  
  {
    name: 'AeroJet',
    fuelCapacity: 800
  },
  {
  
  	name: 'SkyJet',
    fuelCapacity: 500
  }
 ];

Why not state the properties like this:

let Airplane = {
  
  
  availableAirplanes =[
  
  {
    name: 'AeroJet',
    fuelCapacity: 800
  },
  {
  
  	name: 'SkyJet',
    fuelCapacity: 500
  }
 ];
  
  
};

#2

in this case, i would certainly opt for adding the properties in the object

however, its good to know that we can add properties to an object after we defined it, this might come in handy in the future. Codecademy mostly teaches concepts, these concepts might not always be the best for the given scenario, but a simplified scenario explains the concept better.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.