From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext

Unlock this course with a free trial

Join today to access over 25,000 courses taught by industry experts.

Learn about JavaScript classes

Learn about JavaScript classes

- Many of you who are coming to JavaScript from languages like Java and are used to coding in a primarily object-oriented manner are probably aching to see how to define classes in JavaScript and how to use them. But before we get into that, it's important to note that the behind-the-scenes details of classes and inheritance in JavaScript might be a little different than you were expecting. The main difference is that instead of class-based inheritance, which is most likely what you're used to working with, JavaScript uses something called prototypical inheritance. We'll go over that in more detail shortly. First, let's take a look at how to define classes and create instances of them. The most basic way of defining a class is by using the class keyword. So for example, we can say class Person with brackets that contain the body of the class definition. Simple enough. Now what if we wanted to find some member variables for our Person class, such as name and age? Well, the way we do…

Contents