Skip to main content

JavaScript Classes

12 lessonsAbout 72 minutesIntermediate

This part of the JavaScript Tutorial runs from JavaScript Classes through to JavaScript Prototype Chain. There are 12 lessons here, and working through them takes about 72 minutes at a steady pace.

It follows on from JavaScript Asynchronous, so finish that first if you have not already — the examples below assume you are comfortable with it.

Each lesson below says what it covers before you open it. Read them in order the first time; afterwards this page works as a index you can jump back into when you need to check one thing.

  1. 1JavaScript ClassesA JavaScript class is a template for creating objects that share the same shape.
  2. 2JavaScript Class ConstructorThe constructor runs when an instance is created and sets up its properties.
  3. 3JavaScript Class MethodsClass methods are functions shared by every instance of the class.
  4. 4JavaScript Class FieldsClass fields declare properties directly in the class body.
  5. 5JavaScript Static MembersStatic members belong to the class itself rather than to any instance.
  6. 6JavaScript Class Inheritanceextends creates a class that inherits everything from another class.
  7. 7JavaScript super Keywordsuper calls the parent class constructor or one of its methods.
  8. 8JavaScript Method OverridingA child class can replace a method it inherited with its own version.
  9. 9JavaScript Private FieldsA field starting with a hash is private and cannot be read from outside the class.
  10. 10JavaScript Class Getters and SettersClass getters and setters let a method be used like a plain property.
  11. 11JavaScript instanceofinstanceof checks whether an object was built from a particular class.
  12. 12JavaScript Prototype ChainEvery object has a prototype, and lookups walk up the chain until they find a match.