JavaScript classes key concepts

Posted November 20, 2016

Taken by Mia Baker

The key concept in class variables and methods is how to define them. Classes are realistically just “special functions”. To define a class, you use the keyword class followed by the name you want to give it.

1class myClass {
2 constructor(height, width) {
3 this.height = height;
4 this.width = width;
5 }
6}

When you’re defining classes make sure they are hoisted or your code will throw errors like

1var p = new myClass(); // ReferenceError
2class myClass {}

It should be known that the content of a class declaration is executed in strict mode.