Why this pointing to global context is giving undefined, even when global variable is defined ?
Author: utkarsh-1602Created Feb 22, 2024Updated Dec 21, 2024
this is my program
var status = "online"
setTimeout(() => {
const status = "offline"
const data = {
status: "not responding",
getStatus(){
return this.status;
}
}
console.log(data.getStatus())
console.log(data.getStatus.call(this))
}, 0);
why console.log(data.getStatus.call(this)) is returning undefined ?
Source: trekhleb/javascript-algorithms