ECMAScript constructor

Basically we can override the ECMAScript constructor, for example we will assign a value to the a variable of the hello class and return a new instance of that class to the method caller.

(function() {
class hello {
	constructor(a) {
		this.a = a;
		return this;

console.log(new hello("hello").a); //output hello
console.log(new hello("hello") instanceof hello); //output true


If the class’s constructor does not return anything then the default value which is the new instance of that class will be returned.

Like this post? Kindly share!