Constructor in Javascript

 Constructor in Javascript

In this article we are goanna to see about Constructor in Javascript and where we use these. which is most important when you are going to start your career in JavaScript. Please ready and enjoy this article if you want to give any feedback about your experience, we welcome.


Constructor is special function that prepare new instance of an object for use.

Example:

function Mobile( ){

this.model = “mi 9 pro”,

this.price = function( ){ document.write(this.model + “Price 3000”);

}

}

var redmi = new Mobile();

document.write(redmi.model + redmi.price( ));

Constructor with parameter:

Example:

function Mobile(model_name ){

this.model = model_name,

this.price = function( ){ document.write(this.model + “Price 3000”);

}

}

var redmi = new Mobile(“mi 9”);

document.write(redmi.model + redmi.price( ));


Share:

0 comments

Please leave your comments...... Thanks