I would add something to PortableStick’s answer because the technical differences are a concept I’m just starting to learn. I’d like to test some of my own knowledge by answering this question more in depth.
Languages that use “Classical Inheritance” (languages that PortableStick provided examples of above) do not allow new instances of objects to exist without extending an existing class. i.e.:
class Vehicle {}
obj Car extends Vehicle {}
So, the classes and objects derived from a parent class implicitly gain (“inherit”) the properties and methods of their parent.
JavaScript, on the other hand, definitely does not use classical inheritance - try asking your dev tools console:
new Object();
And for me, using the word “delegation” to describe JavaScript’s prototype-based behavior, instead of inheritance, has been useful. Instead of child objects implicitly gaining, or inheriting the data encapsulated inside a parent class, JavaScript objects “delegate” up the prototype chain. Here’s an example that’s helped me:
let foo = {
a: 1
};
let bar = Object.create(foo);
bar.a; // 1
foo.a; // 1
bar.hasOwnProperty('a'); // false
foo.hasOwnProperty('a'); // true
Here, the interpreter looks at bar.a
and returns 1. However, when asked bar.hasOwnProperty('a')
, the result is false
. This is because, having no success checking bar
for a property a
, (and returning false) the interpreter looks up the prototype chain to the object the bar
is delegating to, and a
is defined on foo
, so we find that foo.hasOwnProperty('a');
is true
So - long story short - when freeCodeCamp says:
This is to be noted, that the class syntax is just a syntax, and not a full-fledged class based implementation of object oriented paradigm, unlike in languages like Java, or Python, or Ruby etc.
What they mean is the implementation of class
in JavaScript is functionally very different than what is actually happening when we think about classical inheritance in another language. JavaScript has its own awesome way of doing things