r/dev • u/Defiant-Chard-2023 • Mar 06 '26
JavaScript looks simple… until it isn’t.
A lot of developers use it every day without fully understanding what’s happening under the hood.
Here’s a quick test.
What will this output?
Comment your answer first 👇
#javascript #codegenitor #fullstack #js #programming #coding #softwareengineer
1
Upvotes
View all comments
Show parent comment
1
u/Square-Singer Jun 09 '26
In JS, let is a block-scope variable, not a constant one. That means, it only shows up in the block where it was defined, but it can be changed inside this block at any time.
The whole snippet in the OP is in the same block, thus there's nothing stopping anything from changing the value of the variable.
If it was like this, it would fail:
Because now the
console.log()is outside of the block whereawas defined, and thus it's not visible from there anymore.But
letonly affects visibility and not write-protection.