Dev Helpers

JavaScript / Practical transformations

Sum distances with a Euclidean norm

Dev Helpers · December 6, 2026

A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.

Worked example

console.log(Math.hypot(3, 4));

Result

5

Implementation notes

Treat the coordinates as lengths in the same unit before combining them. A pixel distance on one axis and a percentage on the other cannot produce a meaningful diagonal until converted.

Try it yourself

Try a three-by-four displacement, then reverse one direction. The length should remain five.

Open the JavaScript example →

Editorial date December 6, 2026 · Published December 6, 2026

Related articles

Build an OS-independent path

Path conventions belong to the destination. Use an explicit path flavour when generating portable asset names.

Resolve ranked ties

A leaderboard needs an explicit tie policy. Ranking tied scores and sorting their display order are separate decisions.

Get the last day of a month

Day zero of the following month falls on the final day of the requested month. Date handles the year rollover for December.