0

Is this.name a declaration of a variable name?

3rd Sep 2016, 9:26 PM
Daniel kabeya kakona
Daniel kabeya kakona - avatar
2 Réponses
+ 3
this keyword holds the current object reference. if we are not using this keyword in below code, it will give output as undefined. example:- <p id="demo"></p> function person(first, last, age) {     this.firstName = first;     this.lastName = last;     this.age = age; } var p1 = new person("xyz","pqr", 40); var p2 = new person("abc","def", 30); document.getElementById("demo").innerHTML = "first person age is " + p1.age +". second person age is " + p2.age; output :- first person age is 40. second person age is 30
4th Sep 2016, 3:00 AM
Nishant
Nishant - avatar
+ 1
thanks a lot
4th Sep 2016, 3:59 AM
Daniel kabeya kakona
Daniel kabeya kakona - avatar