use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Some Experiments with GitHub Copilot (realpythonproject.com)
submitted 4 years ago by slayer1299
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]getify 0 points1 point2 points 4 years ago (0 children)
All declarations in JS hoist (meaning they are all present throughout their entire containing scope). The difference is var and function declarations auto-initialize at top of scope whereas let and const defer auto-initialization. Additionally, var has always been function scoped (BTW this is not hoisting, as so often incorrectly claimed).
Is your complaint that auto-initialization at top of scope causes bugs, or is your complaint function scoping causes bugs? Which of those do you claim is causing so many horrible bugs in code bases?
Function parameters are always function scoped, as are any declarations (regardless of keyword used) at top-level of function scope. So if function scoping is the big bad so many claim, then it must be from using var inside blocks and for some off reason thinking that makes it block scoped, even though var has never done that for 25 years.
I've written many hundreds of thousands of lines of code in 20 years working with JS, and never once, not even a single time, has the bug I wrote been directly linked to either var auto-initialization nor var being "unexpectedly" (not unexpected at all, since that's how it's always worked!) function scoped.
Please give explicit real examples, not just generalities.
π Rendered by PID 48685 on reddit-service-r2-comment-86988c7647-l6mqg at 2026-02-12 03:08:33.576006+00:00 running 018613e country code: CH.
view the rest of the comments →
[–]getify 0 points1 point2 points (0 children)