JS Built-ins
← Math129 / 215
Mathhypotintermediate

Math.hypot() β€” Unit Diagonal

πŸ“– Usage Example
// Euclidean distance / hypotenuse
Math.hypot(3, 4)   // β†’ 5
Math.hypot(5, 12)  // β†’ 13

Use Math.hypot() to calculate the hypotenuse of a right triangle or Euclidean distance between points.

Math.hypot()

Returns the square root of the sum of squares of its arguments.

Challenge: Compute the diagonal of a unit square using Math.hypot(1, 1), which should equal √2.

πŸ’‘ Hints (1)
  • β€’ sqrt(1^2 + 1^2) = sqrt(2) = Math.SQRT2 β‰ˆ 1.41421356...