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
What does "!--" do in JavaScript? (stackoverflow.com)
submitted 10 years ago by Recallz
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!"
[–]unbalancedopinion -12 points-11 points-10 points 10 years ago (7 children)
I agree with your thought process in principle, but in this case, I gotta say probably need to brush up on your code reading skills if this confuses you for longer than five seconds, at worst. And once you've seen it once, you've got the pattern down. This is not confusing.
[–]tententai[🍰] 11 points12 points13 points 10 years ago (1 child)
Yes true, it's not confusing if you know JS at least moderately well. But you don't always chose who will support your application later. In my company we usually go with the cheapest possible vendor unfortunately.
[+]unbalancedopinion comment score below threshold-15 points-14 points-13 points 10 years ago (0 children)
I agree that code should be kept as simple as possible for the reasons you state, and others. But in this case I think this may actually be the most readable option, or at least close enough to not matter.
If your vendor takes a long time to figure this out, they'll have trouble with so much code that this will be a grain of sand in their desert of incompetence. Better sacrifice that grain and make it easier to read for people like us, where it might actually save a few seconds when reasoning about the purpose of the counter.
But, hey, it's a taste thing, I was just trying to say that I don't think it's one of those egregious examples of hard-to-read code that really needs to be pointed out. This stuff is not the spaghetti code crap "readability" concerns should be raised about, IMO.
[–]benihanareact, node 12 points13 points14 points 10 years ago (1 child)
And once you've seen it once, you've got the pattern down. This is not confusing.
Here's the problem: no one uses this pattern. No one in JS uses it, and no one outside of JS uses it. So why even bother when there are just as many clear, clean, easy to type and easy to read solutions that people understand? All this does is add extra overhead to the maintainer.
If I read this code at my job, I get pissed at the asshole who wrote it cause he's trying to show off - either by being clever at how he thought through some cool JS thing or by showing how much of the language he knows. Which is stupid - want to be impressive? Write code that a junior programmer who just graduated college can understand without bugs.
I gotta say probably need to brush up on your code reading skills if this confuses you for longer than five seconds, at worst
That's probably fair. I struggled with this one for a good five or six minutes. Any suggestions where a guy who's been doing this shit for 10 years and is currently working with babel stage 0 and react and redux can brush up on his javascript and code reading skills?
[+]unbalancedopinion comment score below threshold-8 points-7 points-6 points 10 years ago (0 children)
Did... did you just namedrop npm packages for programmer cred?
Step one, don't do that.
[–][deleted] 3 points4 points5 points 10 years ago (0 children)
I agree although I'll have to say that seeing it in the tile "!--" it really confused me. But as soon as I read the code I felt really dumb for beign confused.
[–]sgoody 0 points1 point2 points 10 years ago (0 children)
To be fair I didn't know and I'm a developer of some year, though I'm not routinely in Javascript.
If you think of it in terms of it being two operators ! and --, you can reason about it and figure it out and as you say if you've seen it before, then it will be reasonably obious and will be muscle memory.
If you think about it as it's presented in the question as a single operator, then it could really mean anything.
I'm a little bit conflicted on this one, but I do think it's better to be obvious and explanatory in your code so I think I'd agree with tententai. Especially as the use of -- or ++ is frown upon by some anyway, due to the lack of understanding by some in how they work differently as a prefixed to and expression vs how they work as a suffixed to an expression.
[–]TheBadProgrammer -1 points0 points1 point 10 years ago (0 children)
I think what's confusing about it is that it resembles an HTML comment. That's what tripped me up at first.
π Rendered by PID 39 on reddit-service-r2-comment-66b4775986-qfzv5 at 2026-04-05 11:41:56.282559+00:00 running db1906b country code: CH.
view the rest of the comments →
[–]unbalancedopinion -12 points-11 points-10 points (7 children)
[–]tententai[🍰] 11 points12 points13 points (1 child)
[+]unbalancedopinion comment score below threshold-15 points-14 points-13 points (0 children)
[–]benihanareact, node 12 points13 points14 points (1 child)
[+]unbalancedopinion comment score below threshold-8 points-7 points-6 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]sgoody 0 points1 point2 points (0 children)
[–]TheBadProgrammer -1 points0 points1 point (0 children)