function User(firstName,EmailId){
this.name = firstName;
this.email = EmailId;
this.quizScores = [];
this.currentScore = 0;
}
User.prototype = {
constructor : User,
saveScore:function (scoreToAdd) {
this.quizScores.push(scoreToAdd)
},
showNameAndScores:function () {
var scores = this.quizScores.length > 0 ? this.quizScores.join(",") : "No Scores Yet";
return this.name + " Scores: " + scores;
},
changeEmail:function (newEmail) {
this.email = newEmail;
return "New Email Saved: " + this.email;
}
}
secondUser = new User("Peter", "[email protected]");
console.log('secondUser',secondUser);
secondUser.changeEmail("[email protected]");
secondUser.saveScore(18);
secondUser.showNameAndScores();
On my console I see output as
currentScore:0
email:"[email protected]"
name:"Peter"
quizScores:[18]
Now in my above code I have created object and then immediate printed on console then I have called prototype methods still it print values updated by prototype methods.why it happens?

