Construct JavaScript Objects with Functions

These two programs do the exact same thing, right?
var MotorBike = function() {
this.wheels = 3;
this.engines = 1;
this.seats = 1;
};
and,
var motorBike = {
“wheels”: 2, “engines”: 1, “seats”: 2
};

Your code so far

var Car = function() {
  this.wheels = 4;
  this.engines = 1;
  this.seats = 5;
};

// Only change code below this line.

var MotorBike = function() {
  this.wheels = 3;
  this.engines = 1;
  this.seats = 1;
};


Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0.

Link to the challenge:
https://www.freecodecamp.org/challenges/construct-javascript-objects-with-functions

Nope :confused:
The first ‘program’ you wrote is a ‘constructor’, the second is a custom object;
As stated in the challenge:
In a constructor the this variable refers to the new object being created by the constructor.

You will use it as follows:

let test = New motorbike();
console.log( test.wheels) // result 3

`

The second one is an object: you use it to store and manage data.

Here’s a useful link: MDN - Workng with object

Hope it helps,
-LyR-

Is the reason one uses the constructor function instead of the custom object is so one can add more objects?

That is one of the effect if i understand what you mean.
The constructor is something like a ‘mould’: you use it to produce ‘istances’ ( the objects you ‘produce’ with that mould) ; a simple object is something ‘handcrafted’.
The differences between these two ways to create an object are the same of the factories counterpart : you will go for an handcrafted item when you want something full customizable and not to be ‘rebuilded’, a constructor is preferred to be defined when you need to produce more than one item ( or if you plan to do so, or if you want to implement a structure ‘potentially’ reusable etc…)

This is my opinion, if i said something wrong please correct me; if someone would add something it would be good since there are a LOT of stuff behind that ( constructors could be considered as one of the main components of the classes, which are the bases of the OOP approach).

Are these just two ways to create objects? I can either create an object with ‘objects as variables’.
example:
Before:

var car = {
  "wheels":4,
  "engines":1,
  "seats":5
};

After:

var car = {
  "wheels":4,
  "engines":1,
  "seats":5,
  "mirrors":3
};

Or I can create an object with constructor functions.
example:
Before:

var Car = function() {
  this.wheels = 4;
  this.engines = 1;
  this.seats = 5;
};

After:

var Car = function() {
  this.wheels = 4;
  this.engines = 1;
  this.seats = 5;
};
var myCar = new Car();
myCar.mirrors = 3;