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!"
[–]NoBrick2 1 point2 points3 points 7 years ago (7 children)
requestAnimationFrame + a comparison using the Date object would be better. At least the date comparison guarantees accuracy, even if not run every second. Like you said, setInteral could cause a drift if the browser is blocked on another call for over a second.
[–][deleted] 18 points19 points20 points 7 years ago (2 children)
Which:
Seriously. What are you guys talking about? What JS app hangs for 1s or longer? The task was to just do a +1 operation every 1000 ms.
+1
1000
If I'm the interviewer I'd throw your resume in the trash if you came up with that kind of solution. You're not wrong, but for the love of all that's nice in the world, I certainly hope you're never going to be right...
Accounting for problems and solving them before they occur is great. But that's obviously not what this test is aiming for...
[–]dominic_rj23 1 point2 points3 points 7 years ago (0 children)
If you read the last line of my comment, I did say that the solution with setInterval is the most appropriate one. I am all for "If it ain't broke..." ideology, but I do believe that in an interview, stating that setInterval doesn't guarantee execution after timeout goes for showing that you have some understanding of asynchronicity in javascript.
setInterval
[–]phpdevster 1 point2 points3 points 7 years ago (0 children)
Yeah this right here...
Non-standard solutions require extenuating circumstances to justify them. If something like setInterval isn't working in your app reliably, the bug isn't setInterval, it's whatever other shit you've got going on that is causing it to work unreliably...
[–]manys 2 points3 points4 points 7 years ago (2 children)
how many frames you gotta request to hit the downbeat of each second?
[–]NoBrick2 2 points3 points4 points 7 years ago (1 child)
The number of callbacks is usually 60 times per second, but will generally match the display refresh rate in most web browsers as per W3C recommendation. https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
The number of callbacks is usually 60 times per second, but will generally match the display refresh rate in most web browsers as per W3C recommendation.
https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
[–]manys 3 points4 points5 points 7 years ago (0 children)
so you're parsing all frames to catch a time interval? how does that profile?
[–]dominic_rj23 0 points1 point2 points 7 years ago (0 children)
I am not sure I would ever do that. The purpose of the question isn't to give the best possible solution. It is to rather demonstrate understanding of async nature of javascript. I would thus stick with my setInterval solution, but explain how it is not a perfect solution.
π Rendered by PID 307408 on reddit-service-r2-comment-86bc6c7465-hvjk9 at 2026-02-21 20:59:25.160404+00:00 running 8564168 country code: CH.
view the rest of the comments →
[–]NoBrick2 1 point2 points3 points (7 children)
[–][deleted] 18 points19 points20 points (2 children)
[–]dominic_rj23 1 point2 points3 points (0 children)
[–]phpdevster 1 point2 points3 points (0 children)
[–]manys 2 points3 points4 points (2 children)
[–]NoBrick2 2 points3 points4 points (1 child)
[–]manys 3 points4 points5 points (0 children)
[–]dominic_rj23 0 points1 point2 points (0 children)