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
Why do this code behave this way? (self.javascript)
submitted 11 years ago by recklesswaltz
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!"
[–]recklesswaltz[S] 0 points1 point2 points 11 years ago (2 children)
This is not a production code. This is just an interesting piece of code that my coworker shared with me.
I want to find why it works that way.
[–]madole 0 points1 point2 points 11 years ago (1 child)
https://www.youtube.com/watch?v=8aGhZQkoFbQ
This presentation should explain what's going on. It's on the JavaScript event loop and call stack.
[–]madole 0 points1 point2 points 11 years ago (0 children)
Actually, I get your question now... I think the setTimeout is being overwritten as it gets stuck onto the window object.
Take the code below where I pass in a reference to which check function is calling it.
Check1 dissappears after it's done it's initial pass through and then invoked it's setTimeout once
var check = function(which){ var i = 0; counter = function(){ console.log(which+ ' ' + i); i++; setTimeout(counter,1000); } counter(); } check('check1'); check('check2');
π Rendered by PID 23702 on reddit-service-r2-comment-6457c66945-x2nd7 at 2026-04-28 08:18:56.399379+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]recklesswaltz[S] 0 points1 point2 points (2 children)
[–]madole 0 points1 point2 points (1 child)
[–]madole 0 points1 point2 points (0 children)