how to create the class in javascript code example

Example 1: create element javascript with class

// create div element by javascript with class

var div = document.createElement('div');
div.className = "div1";

Example 2: class in javascript

class Car {
    constructor(name, year) {
        this.name = name;
        this.year = year;
    }
    age(x) {
        return x - this.year;
    }
}

let date = new Date();
let year = date.getFullYear();

let myCar = new Car("Ford", 2014);
document.getElementById("class1").innerHTML = "My car is " + myCar.age(year) + " years old.";