JavaScript Classes and Object Creation

In this lesson, we briefly look at object-oriented programming concepts in JavaScript like classes and objects.

Background

Classes are relatively new to JavaScript as previously, there was only JavaScript’s prototype chain which could be used for inheritance too. JavaScript classes build up on top of the prototypical inheritance giving the whole thing a more straightforward representation. Classes in JavaScript are syntactical sugar over prototype chains. You don’t need to understand what a prototype chain or prototypical inheritance is for this course but knowing these concepts would give you some​ context of classes in the language.

What is a class?

A class is a kind of separate mini-program with a context of its own — methods (functions) and properties (variables). They describe an entity in a way that a computer can understand.​ Disparate ‘instances’ (called objects) of a class can be created and treated as variables. Let’s examine the following code to learn how classes work in JavaScript.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy