A nested lexical binding can hide an outer value without mutating it. Logging before and after the block reveals which value each reader sees.
Worked example
const colour = "ink";
{
const colour = "clay";
console.log(colour);
}
console.log(colour);Result
clay
inkImplementation notes
Shadowing is useful when a narrowed binding has a short scope. When both bindings represent different domain concepts, distinct names make an accidental read easier to notice.
Try it yourself
Move a read across the closing brace and compare the result.
Open the JavaScript example →Editorial date August 30, 2025 · Published December 6, 2026