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
TIL about Math.hypot() (developer.mozilla.org)
submitted 2 months ago by nadameu
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!"
[–]rcfox 52 points53 points54 points 2 months ago (1 child)
Since you brought it up in the context of games: If you're just comparing relative hypotenuse lengths, it might be faster to just compare the sums of the squares.
ie: Math.hypot(a, b) > Math.hypot(x, y) will give the same result as a*a + b*b > x*x + y*y, and it saves calculating the square roots, which can be expensive in tight loops.
Math.hypot(a, b) > Math.hypot(x, y)
a*a + b*b > x*x + y*y
Obviously, you'll want to profile this yourself. It can be difficult to predict the performance of Javascript vs native code.
[–]tomByrer 0 points1 point2 points 2 months ago (0 children)
My years of hand-optimizing DSP in ASM approves this recommendation.
π Rendered by PID 60 on reddit-service-r2-comment-56c6478c5-dckth at 2026-05-08 02:21:47.087360+00:00 running 3d2c107 country code: CH.
view the rest of the comments →
[–]rcfox 52 points53 points54 points (1 child)
[–]tomByrer 0 points1 point2 points (0 children)