r/learnjavascript • • Oct 23 '26

Block Scope

What is it? Don't understand what is inside or outside

12 Upvotes

8 comments sorted by

View all comments

1

u/CelebrityChess Oct 24 '26

easiest way to think about it is each pair of curly braces is a room. let and const only exist in the room where you declared them, plus any rooms nested inside it. so k lives in the inner braces, and j lives in the function's braces, which means the inner block can see j but the rest of the function can't see k. inner can look out, outer can't look in, that's pretty much the whole rule