Skip to content
dreamcode
dreamcode
Map
Classes & OOP
Lesson 28 of 48
+15 XP on finish
JAVASCRIPT CLIMBSChapter 5 · JS Functions and Classes

JS ES6 Classes

JavaScript classes are templates for creating objects. They encapsulate data with methods and support constructor methods.

Worked example

How it reads

  • constructor(...) initializes the new object properties
  • this refers to the specific instance of the class
Cloud tip: Class syntax is syntactical sugar over JavaScript's existing prototype-based inheritance model.
index.js
JAVASCRIPT
real JavaScript, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Give Star a method describe() that returns "Vega shines" (use this.name) and log s.describe().

Press Run to check your work.