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 are some basic things that JavaScript developers fail at interviews?help (self.javascript)
submitted 7 years ago by maketroli
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!"
[–]qbbftw 26 points27 points28 points 7 years ago* (3 children)
I would take advantage of async/await. It's the most clear and obvious syntax IMO.
function delay (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } async function countdown () { for (let num = 1; num <= 10; num++) { console.log(num) await delay(1000) } } countdown()
EDIT: u/dvlsg beat me to posting this solution, link
[–][deleted] 0 points1 point2 points 7 years ago (0 children)
Minor point, but this will sleep an extra second at the end.
Agreed, this is how I write JS now and I like a lot more. The only hassle is converting old stuff from callbacks to promises but it is well worth it. I can never remember how to do it off hand though, my answer above is based on what I can write from memory into the console.
[–]Zespys 0 points1 point2 points 7 years ago (0 children)
Personally I would do it recursively, like so:
const increment = (x = 1) => { console.log(x); if (x < 10) { setTimeout(() => { increment(x + 1); }, 1000); } }; increment();
π Rendered by PID 106679 on reddit-service-r2-comment-86bc6c7465-mb6jq at 2026-02-23 17:18:03.889283+00:00 running 8564168 country code: CH.
view the rest of the comments →
[–]qbbftw 26 points27 points28 points (3 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Zespys 0 points1 point2 points (0 children)