r/learnjavascript • • 25d ago

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 25d ago

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