Skip to main content
JAVASCRIPT-BASICS5 MIN READ

Make scope visible before you debug

Predict whether a JavaScript variable is visible from a given line of code.

The move: draw the room before blaming the value. JavaScript names live in scopes. A scope answers one question: from this line of code, which declarations can I see? When the code runs in a browser or Node, the engine does not search randomly. It checks the current scope first, then walks outward through parent scopes until it finds the name or throws a reference error. Block scope let and const are block-scoped. A pair of braces can create a boundary: if, for, while, and plain blocks all matter. Use this when a value is temporary and should not leak…

Read the full lesson

Sign up free — one personalized lesson every day, matched to your role and goals.

Already have an account? Sign in

← Back to library
Contact us