Learning object 33 of 100
Scope chain explorer
Step through nested blocks, functions and calls, and watch which scope each variable lives in and how the call stack grows and shrinks.
Loading…
What it shows
Every block and function call creates a scope. A name is looked up in the current scope first and then outward through the scopes the code is written inside: the scope chain. Calling a function pushes a frame on the call stack; returning removes it and the caller continues.
Guided experiment
- In Block scope, step into the if block. Which variables are visible there?
- In Lexical lookup, predict which label show prints before stepping.
- In Call stack, step until three frames are on the stack.
Predict
A function defined at the top level reads label. A caller has its own local label. Which one does the function read?
Related
Lessons: Lesson 46: Global, function and block scope, Lesson 47: Lexical environments, Lesson 50: Understanding execution contexts
Projects: Project 9: Shopping Cart Price Calculator
Source: web/assets/js/objects/object-033.js in the companion repository.