0
Is this.name a declaration of a variable name?
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
+ 1
thanks a lot