TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

In defense of blocks for local scopes

27 pointsby jacobralmost 3 years ago

4 comments

culturedsystemsalmost 3 years ago
If your code is sufficiently distinct that block scope is useful, and there's no obvious contextual clue as to why it's distinct (like an if statement), put it in a separate function to explain why it's distinct. The article mentions this argument, but responds with some handwaving about how technically it's valid JS to use an unnamed block statement. I mean, sure, but does that mean it's a good idea?
评论 #31880158 未加载
评论 #31879720 未加载
评论 #31879725 未加载
评论 #31882690 未加载
评论 #31880756 未加载
teg4n_almost 3 years ago
I’ll just cross my fingers for do expressions getting adopted. Before then functions work for me and none of the gist convinced me otherwise.
评论 #31880987 未加载
评论 #31880827 未加载
tengbretsonalmost 3 years ago
How about don't use let or var declarations at all?
评论 #31881177 未加载
duxupalmost 3 years ago
I had no ideas this was an option in JavaScript.<p>Fun read.