What Is an Object?

Now that you’ve learned how to create a Class, it’s time to understand Objects.

You’ve already seen objects in previous examples, so this concept should feel familiar.

The idea is simple:

  1. Create a Class.
  2. Create an Object from that class.
// Model
class Car {
constructor() {
console.log("This is a car model");
}
}
// Object
const car = new Car();

Why Store an Object in a Variable or Constant?

You might wonder:

  • Why do we use const?
  • Can we use var instead?
  • Can we create an object without storing it?

The answer is yes. All of the following are valid:

// Constant
const car = new Car();
// Variable
var car = new Car();
// Create directly
new Car();

The difference isn’t about correctness—it’s about how you plan to use the object.

If you’ll use the object multiple times, storing it in a variable or constant makes your code cleaner and avoids repeating the creation step.

If you only need it once, creating it directly is perfectly acceptable.

Why Is const Commonly Used?

In most JavaScript codebases, you’ll see objects stored in const.

const car = new Car();

This is considered a best practice because we usually don’t intend to reassign the variable to another object later.

Keep in mind that const does not make the object immutable. It only prevents the variable from referencing a different object.

What Does new Do?

The new keyword creates a new object from a class.

For example:

const car = new Car();

This tells JavaScript to create a new instance of the Car class.

You can create as many objects as you want from the same class.

const car1 = new Car();
const car2 = new Car();
const car3 = new Car();
const car4 = new Car();

Each object is independent, even though they all come from the same class.

Using the car analogy, the Class is the blueprint, while every call to new Car() produces a brand-new car built from that blueprint.

Key Takeaways

  • Objects are created from classes using the new keyword.
  • A single class can create any number of objects.
  • Objects can be stored in const, var, or created directly, depending on your needs.
  • Using const is generally considered the best practice because object references are rarely reassigned.