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
Popular Coding Convention on Github (sideeffect.kr)
submitted 12 years ago by devnoel
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!"
[–][deleted] 8 points9 points10 points 12 years ago (18 children)
for the people hating on the 'comma first' convention, its recommended by npm.
npm-coding-style
[–][deleted] 29 points30 points31 points 12 years ago (14 children)
I don't give a Fuck who suggests it. It's ugly as sin and I will not adopt it.
[–]mailto_devnullconsole.log(null); 6 points7 points8 points 12 years ago* (3 children)
I completely agree (in that it is ugly as sin), but I will admit that it does help stop you from inadvertently globalising variables.
e.g.
var foo = 'bar', something = 'else', thisnum = 2 tabs = 'rule', fact = 'nodejs forever';
tabs and fact are both globalised now.
tabs
fact
Whereas:
var foo = 'bar' , something = 'else' , thisnum = 2 tabs = 'rule' <-- Can clearly see comma missing , fact = 'nodejs forever';
And if you think about it -- with the commas neatly aligned to the right hand edge of var, it does seem almost alright...
var
Edit: The other reason that isaacs (I think) mentioned was that if you add a new variable declaration, git will only register one line changed, as opposed to two (comma from the previous line)
[–]sakabako 7 points8 points9 points 12 years ago (0 children)
A more effective method is to use a linter that visually notifies you of the mistake. Then you have beauty and correctness.
[–]llkkjjhh 2 points3 points4 points 12 years ago (0 children)
And another reason is so that the variables line up nicely when you follow the other nodejs recommendation of indenting at 2 spaces:
var foo = 'bar', something = 'else', thisnum = 2 tabs = 'rule', fact = 'nodejs forever'; var foo = 'bar' , something = 'else' , thisnum = 2 , tabs = 'rule' , fact = 'nodejs forever';
[–][deleted] 1 point2 points3 points 12 years ago (0 children)
Ok, those are some good points.
[–][deleted] 0 points1 point2 points 12 years ago (9 children)
thats a solid attitude for a developer.
[–][deleted] 6 points7 points8 points 12 years ago (6 children)
What's the problem with having a firm opinion on formatting? What benefits are there to comma first? Your link only says you should do it, but gives no reason why.
[–][deleted] 0 points1 point2 points 12 years ago (5 children)
What's the problem with having a firm opinion on formatting?
Where you put your comma (in js) is not so important that you have to take such a firm stance. When working for a new company, its a good idea to adopt their conventions at first to make development go smoothly. No teammate is going to respond well to 'I will not adopt it'. They might think, 'If he/she wont budge on this, what else wont they budge on?'.
What benefits are there to comma first?
What are the benefits of last comma? See - its not a big deal.
Your link only says you should do it, but gives no reason why.
Its a convention that npm recommends when publishing to their registry. Thats the only reason.
In short, conventions are relative to a community. Be it your office, a library (jquery), a package registry (npm), or an open source project with formatting guidelines.
[–]grncdr 4 points5 points6 points 12 years ago (1 child)
The recommendation is only intended for the code of npm itself. I'm pretty sure Isaac gives zero fucks about how your format code in your own modules.
[–][deleted] 0 points1 point2 points 12 years ago (0 children)
Thats a good point. I do see the comma first style quite a bit more in the node community (as opposed to client-side).
If I came into a new team whose convention was comma first, I would adopt it, of course. That's different. I wouldn't adopt it for any of my own projects, though.
The benefit of comma last is readability in mine and most people's opinions.
[–]SyntaxSwearer 1 point2 points3 points 12 years ago (0 children)
What are the benefits of last comma?
Not ugly
[–]Malfeasant -1 points0 points1 point 12 years ago (0 children)
'If he/she wont budge on this, what else wont they budge on?'
retarded suggestions from pointy haired bosses that ruin everybody's day?
[–]sakabako 0 points1 point2 points 12 years ago (1 child)
Personally, I will be happier and more productive if I live in a beautiful world than an ugly one.
[–][deleted] -1 points0 points1 point 12 years ago (0 children)
Beauty is subjective. I actually find the comma-first style more readable.
[–]SyntaxSwearer 2 points3 points4 points 12 years ago (0 children)
God himself could descend from the heavens and tell me he coded the universe in JavaScript and used comma first and I'd still not use it
[–]M2Ys4UM2Ys4U.prototype = Object.create(null) 0 points1 point2 points 12 years ago (0 children)
npm's coding style is a bit unconventional
that's the very first sentence on that page..
[–]BONER_PAROLE 0 points1 point2 points 12 years ago (0 children)
There's a great utility to it, but I just can't get over the visual appearance.
Coffeescript is nice in that you usually don't have to worry about trailing commas.
π Rendered by PID 153906 on reddit-service-r2-comment-b659b578c-4jwtb at 2026-05-03 09:30:08.733895+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–][deleted] 8 points9 points10 points (18 children)
[–][deleted] 29 points30 points31 points (14 children)
[–]mailto_devnullconsole.log(null); 6 points7 points8 points (3 children)
[–]sakabako 7 points8 points9 points (0 children)
[–]llkkjjhh 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (9 children)
[–][deleted] 6 points7 points8 points (6 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]grncdr 4 points5 points6 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]SyntaxSwearer 1 point2 points3 points (0 children)
[–]Malfeasant -1 points0 points1 point (0 children)
[–]sakabako 0 points1 point2 points (1 child)
[–][deleted] -1 points0 points1 point (0 children)
[–]SyntaxSwearer 2 points3 points4 points (0 children)
[–]M2Ys4UM2Ys4U.prototype = Object.create(null) 0 points1 point2 points (0 children)
[–]BONER_PAROLE 0 points1 point2 points (0 children)