var name = 'Mike';
var person = {
name: 'John',
welcome: function(){
var name = 'Mary';
return 'Hi ' + this.name;
}
}
//person.welcome();
// output is
// Hi John
// I was expecting output to be
// Hi Mary
person.welcome.call();
// output is
// Hi Mike
// In this case since no argument is passed to call so this is window and
// I get that window.name is Mike
var name = ‘Mike’; var person = { name: ‘John’, welcome: function(){ var name
Share
this.namerefers to the object property “name”namerefers to the variable “name”You would get the expected result with
return 'Hi ' + name;