Mid JavaScript

What are classes in JavaScript?

Classes are blueprints for creating objects. They provide syntactic sugar over the

traditional prototype-based inheritance.

Example:

class Person {

constructor(name, age) {

this.name = name;

this.age = age;

const sandeep = new Person("Sandeep", 30);

console.log(sandeep.name); // Sandeep

More from JavaScript Tutorial

All questions for this course