Fairy killers and prototypes
TL;DR: JS doesn’t have classes because it’s prototype based
People usually deal with weird patterns in languages they are learning by trying to bend them into the boundaries of something they are already familiar with. Every time someone says JS has classes a fairy dies :’(
In the class-based approach, the one people are usually more familiar with (Java, Python, Ruby anyone?), objects have, among other things, a state and a behaviour. state is all the data owned by the object, while behaviour identifies the methods you can call on the object.
To provide a blueprint for these objects we use a class and we call instances of the class those objects which conform to the definition.
So far, so good.. where’s the trick?
The trick is that JS belongs to a different family which makes uses of prototypes (it’s called prototype-based programming). In this case we have just one single object (we’re going to refer to it as BaseObject) which is the brick on which we’re gonna build our entire system. You can set properties on BaseObject, these properties are called slots. If we need a certain type of abstraction (where we would normally use classes), we clone (make an exact copy) of BaseObject, add the properties we need by slot manipulation et-voilà!
Ok wait, we now have our abstraction.. how do we define an object which makes use of it? You guessed it.. we clone the abstraction and set the slots we need to give it some state. This is the foundation on the top of which JS is built: Arrays, Function, Number, String.. it all comes from one single Object that was cloned and whose properties were altered.
As you may have noticed, while explaining prototype oriented programming, I haven’t referred once to the notion of class. This is because we just have one instance (BaseObject) and since all the work is done by cloning there are no blueprint definition. That, kids, is why JS has no classes.