DEV Community


Discussion on: Take 'this' Quiz, Understand How 'this' Works in JavaScript

nylen profile image
James Nylen

Hi Annie, a couple of small corrections...

In the explanation for examples 2 and 3:

And because the global object does not know anything about say() function, 'this' is undefined.

Should be something like this instead...

And because the global object does not have a caller property, this.caller is undefined.

In the explanation for example 2:

(if you're using a browser console, you might see "null" (Firefox) or "[url referring to the window object]"(Chrome) instead of "undefined")

I tested in Chrome and Firefox and I get undefined in both browsers. This makes sense, because in these examples this.caller is equivalent to window.caller, which is undefined (unless some code on the current page has set this property).

liaowow profile image
Annie Liao Author

Thank you, James! Yes. That makes much more sense. I was googling around trying to find the simplest explainer, only to complicate my own thought process. Really appreciate your input :)