Object-Oriented Programming (OOP) is a paradigm that models real-world entities as objects with properties and methods. Objects in JavaScript can be created using object literals, constructor functions, factory functions, or classes (introduced in ES6).
If you are coming from a background in Java or C++, you recognize classes are the primary construct by which we organize our code in those OOP languages. JavaScript introduced the class
keyword in 2015 with the release of ES6. Here is an example of defining a class and instantiating it in JavaScript.
With the introduction of the class
syntax in ES6, JavaScript’s OOP approach has become more similar to languages such as Java. In this chapter, we will primarily focus on the class syntax.