I am learning js call() function. When I am executing with the let variable (snippet 2), it's showing the desired result, but, when I run the code with the var (snippet 1), it doesn't give the desired results.
var name={
firstname:"amit",
lastname:"shamit"
}
var callName= function(hometown){
console.log(this.firstname+" "+this.lastname+" "+hometown);
}
callName.call(name,"dehradun");
//o/p: undefined undefined dehradun
let name={
firstname:"amit",
lastname:"shamit"
}
let callName= function(hometown){
console.log(this.firstname+" "+this.lastname+" "+hometown);
}
callName.call(name,"dehradun");
//o/p: amit shamit dehradun