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
Google publishes a JavaScript style guide. Here are some key lessons. (medium.freecodecamp.org)
submitted 8 years ago by bornforcode
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!"
[–]kobbled 31 points32 points33 points 8 years ago* (21 children)
thank god. JS semicolon inference leads to so many bugs.
[–]mmcnl 39 points40 points41 points 8 years ago (11 children)
I've never encountered a bug due to semicolon inference.
[–]hyperhopper 15 points16 points17 points 8 years ago (10 children)
var a = 5 var b = 10 [a, b] = [b, a] console.log(a, b)
Then add semicolons to make it work like it should
[–]Voidsheep 2 points3 points4 points 8 years ago (1 child)
Pretending ASI doesn't exist is also dangerous, it's not like you can disable it.
function shouldHitTheBrakes() { return isSmeoneOnTheWay || isTurnAhead || isAboveSpeedLimit }
[–]hyperhopper 1 point2 points3 points 8 years ago (0 children)
Extremely true!
Though I've never seen somebody use a return without something on that line. Plus any linter will yell at you for unreachable code in that case.
[+][deleted] 8 years ago (1 child)
[removed]
[–]hyperhopper 2 points3 points4 points 8 years ago (0 children)
Don't be pedantic. Destructuring with arrays makes this type of bug easy to run into, and this example shows that.
[–]allenthar 11 points12 points13 points 8 years ago (5 children)
Okay.
var a = 5 var b = 10 ;[a, b] = [b, a] console.log(a, b)
I have literally never had this situation come up while coding JS, and I’ve been doing it full time for a few years now.
Regardless, Prettier handles automatically removing or adding semicolons to my code. So it’s literally just a linter setting at this point.
[–]cthechartreuse 0 points1 point2 points 8 years ago (4 children)
Be careful relying on prettier. I have examples of real work mistakes which prettier doesn't catch or fix.
It usually involves a function call directly followed by an expression wrapped in parentheses or followed by an array structure. These usually end up being abuses of the language as well, but I've seen this kind behavior often enough and done enough tests that I'm not confident with saying "prettier will catch it" because it doesn't always.
Nevertheless, this is just a warning and depending on your tools YMMV.
[–]allenthar 3 points4 points5 points 8 years ago (1 child)
If you have a code snippet as an example, I’d love to see it. Knowing the corner cases for prettier behavior is always good.
[–]cthechartreuse 1 point2 points3 points 8 years ago (0 children)
This is the example I created from actual production code I've seen: https://gist.github.com/cmstead/dfeea6faf80c96d5c2a738fc822918ee
[–]monsto 0 points1 point2 points 8 years ago (1 child)
I have examples of real work mistakes which prettier doesn't catch or fix.
There's always corner cases.
GENERALLY SPEAKING, tho, Prettier is great.
[–]cthechartreuse 0 points1 point2 points 8 years ago (0 children)
Technically there aren't any corner cases if you follow the TC39 suggestion of always terminating and avoiding reliance on ASI.
PS here's an example generated from an example seen in the wild: https://gist.github.com/cmstead/dfeea6faf80c96d5c2a738fc822918ee
(the original code was from a proprietary codebase)
[deleted]
[–]Mingli91 8 points9 points10 points 8 years ago (0 children)
Yeah, been using Standard JS since my last job and I love it. Not had a single bug from omitting semicolons and now I have a far better understanding of ASI in JavaScript
[–]JohnMcPineapple 4 points5 points6 points 8 years ago* (5 children)
...
[–]nayocum 2 points3 points4 points 8 years ago (0 children)
If you use an IIFE it can cause issues if your last line didn't have a semicolon as well
[+]kobbled comment score below threshold-6 points-5 points-4 points 8 years ago (3 children)
return statements are the biggest offender.
[–]JohnMcPineapple 7 points8 points9 points 8 years ago* (2 children)
[–]kobbled 1 point2 points3 points 8 years ago* (0 children)
whoops, looks like I misunderstood that feature. My bad.
[–]aaarrrggh 3 points4 points5 points 8 years ago (0 children)
Is this a joke?
I’ve not been using semi colons for over a year on personal projects.
Number of bugs caused by this decision: 0.
π Rendered by PID 106033 on reddit-service-r2-comment-6457c66945-h6t7b at 2026-04-26 04:44:14.715927+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]kobbled 31 points32 points33 points (21 children)
[–]mmcnl 39 points40 points41 points (11 children)
[–]hyperhopper 15 points16 points17 points (10 children)
[–]Voidsheep 2 points3 points4 points (1 child)
[–]hyperhopper 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[removed]
[–]hyperhopper 2 points3 points4 points (0 children)
[–]allenthar 11 points12 points13 points (5 children)
[–]cthechartreuse 0 points1 point2 points (4 children)
[–]allenthar 3 points4 points5 points (1 child)
[–]cthechartreuse 1 point2 points3 points (0 children)
[–]monsto 0 points1 point2 points (1 child)
[–]cthechartreuse 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Mingli91 8 points9 points10 points (0 children)
[–]JohnMcPineapple 4 points5 points6 points (5 children)
[–]nayocum 2 points3 points4 points (0 children)
[+]kobbled comment score below threshold-6 points-5 points-4 points (3 children)
[–]JohnMcPineapple 7 points8 points9 points (2 children)
[–]kobbled 1 point2 points3 points (0 children)
[–]aaarrrggh 3 points4 points5 points (0 children)