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

349 viewsOther

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

😭 TIA.

In: Other

5 Answers

Anonymous 0 Comments

It means the same thing in every Object Orented Language

A class is a descriptor of an Object. So the code you write, all the data, the functions, that is the class.

A class cant used directly since its an abstract description of how you want objects to be made, so to use it, you have to instanciate it and make an instance

An instance is 1 copy of a class, it has its own copy of all the data

A reference is how the language keeps track of the instance. the instance exists somewhere in memory and the reference keeps track of where. If you have a reference to an instance, you can change the instance, and everyone else with a reference to that instance can access the changes.

If you want to change YOUR copy of an instance without changing everyone elses, you have to make a new instance and copy all the data to it (there is usually a copy constructor to do this)

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