What does instance, class, and reference mean in JavaScript?

357 viewsOther

I’m searching online but I’m too… dumb to understand.

😭 TIA.

In: Other

5 Answers

Anonymous 0 Comments

This is more of a fundamental Object-Oriented Programming concept than a Javascript-specific thing.

A **class** is a data structure that represents sone sort of complex object. For example, let’s say we have the class “car”, which represents the idea of a car. What information is there to know about a car? Well, there’s the make, model, color, number of miles, license plate number, owner, and all sorts of other things.

An **instance** is a specific, concrete thing that follows the “blueprint” that the class defines. For example, let’s say I have a truck. Back to our blueprint, this particular car has the following info, so in our example it’s an **instance** of the **car** class:

Make: Ford

Model: Ranger

Color: White

Number of miles: 100,000

License Plate Number: 123ABC

Owner: My buddy John

A **reference** is closer to what it sounds like — a reference to something else. When we include information on an instance, it’s typically “by value” (like the number of miles), or “by reference” (like my buddy John, who himself is an instance of the Person class). Notice, when I’m describing the car instance, I’m *not* telling you my buddy John has brown hair, is 5’11, and has 2 kids. I’m telling you my Car instance is associated with this Person instance, but you can go look at the details of that Person instance if you want more info on it. That’s a reference.

I hope this helps! Feel free to ask for clarification on any point if you’d like. I don’t work with Javascript specifically, but I should still be able to answer some conceptual questions.

You are viewing 1 out of 5 answers, click here to view all answers.