DEV Community

Discussion on: Why JavaScript is an OOP Language (Even Though It Doesn't Have Classes)

Collapse
 
tofl profile image
Tom F.

Javascript (since ES6 I think) also has classes-based OOP. For example :

class Polygon {
  constructor() {
    this.name = "Polygon";
  }
}

var poly1 = new Polygon();

console.log(poly1.name);

I'm guessing that, behind the scenes, it's still PBP.

Collapse
 
andychiare profile image
Andrea Chiarelli

JavaScript classes are syntactic sugar for prototype-based OOP. See dev.to/andychiare/a-matter-of-class