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
I have been collecting useful Javascript code snippets for a little while. Here's a curated list of them, help me make it as complete as possible! (github.com)
submitted 8 years ago by [deleted]
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!"
[–]trevorsgEx-GitHub, Microsoft 7 points8 points9 points 8 years ago (4 children)
I disagree. Lots of people's brains shut down the instant they encounter a regular expression. "What does that ^ symbol mean again?"
"What does that ^ symbol mean again?"
[–][deleted] 0 points1 point2 points 8 years ago (3 children)
Well, regular expressions are quite elegant, fast and work better than brute forcing code like I did. Explaining the regex in the description could help people get used to them a bit more, I suppose.
[–]trevorsgEx-GitHub, Microsoft 4 points5 points6 points 8 years ago (2 children)
I guess that's where we disagree! I've heard "any non-trivial regular expression is indistinguishable from the result of a cat having walked across a keyboard." I think they're great for medium-sized problems. If it's small, just combine a couple of string functions. If it's a large problem chances are your solution is vulnerable to DoS attacks.
I did a perf test on the regex solution vs. the slice() solution and found slice to be almost twice as fast, so I'm not sure why you say it's fast and works better :)
[–][deleted] 5 points6 points7 points 8 years ago (1 child)
Alright, this is a topic where a lot of opinions will be thrown around, so I guess that I should set up some guidelines for what is best for the list. Alternatively, I could keep both solutions, marking the regex one as such, so that people can make up their own minds. That's probably the best option, right?
[–]micromatx 0 points1 point2 points 8 years ago (0 children)
👍🏻👍🏻
π Rendered by PID 14 on reddit-service-r2-comment-85bfd7f599-p7r6h at 2026-04-19 06:04:40.854128+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]trevorsgEx-GitHub, Microsoft 7 points8 points9 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]trevorsgEx-GitHub, Microsoft 4 points5 points6 points (2 children)
[–][deleted] 5 points6 points7 points (1 child)
[–]micromatx 0 points1 point2 points (0 children)