Classes (v1)


JavaScript does not have classes in the same sense as other Object Oriented languages like Java or Ruby. ES6, however, did introduce a syntax for object creation that uses the class keyword. It is basically a new syntax that does the exact same thing as the object constructors and prototypes we learned about in the constructor lesson.

Since we’ve already gone fairly in-depth with Constructors, you don’t have too much left to learn here beyond the new syntax. If you choose to use classes in your code (that’s fine!) you can use them much the same way as object constructors.

Learning Objectives

After this lesson and completing the assignments, you will be able to:

  • Describe the pros and cons of using classes in JavaScript.
  • Briefly discuss the difference between JavaScript’s object creation differs from a language like Java or Ruby.
  • Explain the differences between using a class to define a constructor and other prototype methods.
  • Explain what "getters" & "setters" are.
  • Understand what computed names and class fields are.
  • Describe function binding.
  • Be able to use inheritance with classes.
  • Briefly talk about the conflict in JS with functional programming and classes.


  1. This article provides some pros and cons for classes. There are many people who think that class syntax is misleading for Javascript, and thus Factory Functions (from the previous lesson) are inherently better. WE are not saying that classes are bad! We just want you to be informed on the opinions of both sides.

  2. This article is probably just about all you need to start using class syntax confidently. "Getters and Setters" are a useful feature!

  3. The MDN docs are, as usual, a great resource for going a little deeper. Look especially at the ‘extends’ and ‘Mixins’ sections. React (and other frameworks) uses classes in this way. You create your components and make them extend the core React component which gives you access to all their built-in functionality.


Go back to your "Library" example and refactor it to use class instead of plain constructors. Work on a new branch on the Exercises repository, create a new Pull Request and submit its URL to the Quiz below.

UPDATED: 27.12.2020


  • Is there anything we can help with up to this point? Do you have something to suggest about this chapter? Let us know in the comments below.