And there is that word, “context”. I have heard it several times in my online class and in the Youtube videos, but never really had to think too much about it. Well, that took me to a new tab and a new Google search and here is what that returned via Stack Overflow and a few well written articles (links below):
- Every function invocation has both a scope and a context associated with it.
- Fundamentally, scope is function-based while context is object-based.
- Scope has to do with the the visibility and access of variables
- Context is always the value of the “this” keyword which is a reference to the object that “owns” the currently executing code.
- scope vs. context. Scope is about the environment that code runs in (kind of like a room – – it’s about where the code is) and context is about an actual object that caused some code to be executed (like who was responsible for putting you in that room).
Easy right? LOL. Easy to some, I know, but it sure had me scratching my head. But in the end, I do think I get it and here is my example.
Say I have a JS function such as