Hint
The data structure that stores variable bindings in each scope — the "real" scope implementation
An Environment Record is the actual data structure that stores identifier (variable) bindings for a scope. When the spec says "scope," it means Environment Records under the hood.
// Each scope = one Environment Record created at runtime
// Environment Record stores { variable: value } mappings
function outer() {
let x = 1; // x stored in outer's Environment Record
function inner() {
let y = 2; // y stored in inner's Environment Record
console.log(x); // looks up outer's Environment Record via [[OuterEnv]]
}
inner();
}
// Call stack at inner():
// inner's ER: { y: 2, [[OuterEnv]] → outer's ER }
// outer's ER: { x: 1, inner: fn, [[OuterEnv]] → global ER }
// global ER: { outer: fn, ... }
// Types of Environment Records:
// - Declarative ER: let, const, function declarations, parameters
// - Object ER: var declarations and global code (backed by an object)
// - Global ER: combination of both (global scope)
// - Module ER: ES module scope
// - Function ER: function body scope
// Closures = an inner function holding a reference to
// the outer function's Environment Record AFTER it has returned
const fn = outer(); // outer's ER stays alive because inner references it