Classes: Constructors and Methods
A class describes objects. The constructor sets up each instance, methods are shared and new creates an instance. Use this to access the instance.
Example
class Dog {
constructor(name) { this.name = name; }
bark() { return this.name + " says woof"; }
}
const d = new Dog("Rex");
console.log(d.bark(), d instanceof Dog);Exercise
Create an instance.
const d = Dog("Rex");
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.