You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I guess, when you call "data.getStatus.call(this)", getStatus method setting the value of "this" to global object. But inside getStatus method, "this.status" trying to access global object property , not the status property inside setTimeout.
If we change getStatus function to arrow function, issue will get resolved.
@ManjulaP1012 actually the expected output should be "online" as this is pointing to global object status. but I'm not understanding why its returning undefined
the reason it was returning undefined is that regular functions in Javascript have their own this context which does not automatically refer to the lexical scope of where they are defined that is why as ManjulaP1012 said that using arrow function will resolve it.
@ManjulaP1012 actually the expected output should be "online" as this is pointing to global object status. but I'm not understanding why its returning undefined
this is my program
why
console.log(data.getStatus.call(this))
is returningundefined
?The text was updated successfully, but these errors were encountered: