Creating abstract class in Javascript

An abstract class is a ‘class’ that is used just for inheritance. We should not be creating objects directly from abstract classes.

Here is the code:

function Car(name) {
  if(this.constructor === Car) {
    throw 'Cannot instantiate abstract class';
  } = name;

function i12() {, 'i12');

The key here is the 'constructor' property.

Now, if I execute the following:

c = new i12(); 
console.log(; // "i12"

But trying to instantiate the function 'Car' directly will result in an exception.

c = new Car(); // Uncaught Cannot instantiate abstract class