This lesson will cover two concepts that are crucial to writing strong, robust code and understanding Javascript: Scope and Context. These concepts are also commonly covered in interview questions, since they factor into how we write and organize our code or simply put, how we decide where to put things.
To explore these concepts we will be looking at a series of examples that unveil the mechanics of scope and context. Through comparing and contrasting code examples look that seem similar yet contain important differences, we'll highlight how scope and context operate in Javascript. The examples ultimately aim to illustrate that the way that code is written and structured affects how and where its program data (its variables or references) can be accessed.
Part I: Scope
Part II: Context
- Closely related to the concept of scope is the concept of closures.
- ๐ฅ๐ฅ๐ฅ You Don't Know JS: Scope & Closures ๐ฅ๐ฅ๐ฅ (very detailed)