You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Question:
I’d like to suggest a small adjustment to the code example with the block {} inside the function. While it’s valid JS, using a block like this without a control structure (e.g., if, for, etc.) may be confusing for some readers.
It could be clearer if we used a real control structure, like if (true) { ... }. This would make it more obvious that the block is just creating a new scope, while also demonstrating a more typical use of blocks in JS.
Thanks for considering this!
The text was updated successfully, but these errors were encountered:
Thanks for your response!
Yeah, if (true) { .. } is a bit amusing - I totally see how it might cause that kind of reaction. But I noticed that Get Started already includes similar examples, like:
varadult=true;if(adult){..}
Since if (adult) essentially behaves like if (true), maybe we could use something similar here as well? That way, it would still feel natural while keeping the explanation clear.
In Get Started, it looked pretty clean and intuitive. A standalone {} without any control structure, on the other hand, feels a bit unusual in practice, so I was just thinking about making it blend more seamlessly.
Do you think there’s a way to keep it intuitive for readers while staying true to the explanation?
Please type "I already searched for this issue":
I already searched for this issue
Edition: (1st or 2nd)
2nd
Book Title:
You Don't Know JS Yet: Scope & Closures
Chapter:
Chapter 1: What's the Scope?
Section Title:
Hoisting
Question:
I’d like to suggest a small adjustment to the code example with the block
{}
inside the function. While it’s valid JS, using a block like this without a control structure (e.g.,if
,for
, etc.) may be confusing for some readers.It could be clearer if we used a real control structure, like
if (true) { ... }
. This would make it more obvious that the block is just creating a new scope, while also demonstrating a more typical use of blocks in JS.Thanks for considering this!
The text was updated successfully, but these errors were encountered: