JS Built-ins
← Math50 / 215
Mathacosintermediate

Math.acos() Out of Domain Returns NaN

πŸ“– Usage Example
// Inverse cosine β€” result in radians
Math.acos(1)   // β†’ 0
Math.acos(0)   // β†’ 1.5707... (Ο€/2)

Use Math.acos() to find the angle (in radians) whose cosine equals a given value.

Math.acos(x)

Math.acos() is only defined for inputs in [-1, 1]. Values outside this range return NaN.

Challenge: Verify that Math.acos(2) returns NaN.

πŸ’‘ Hints (2)
  • β€’ The domain of acos is [-1, 1]
  • β€’ NaN is the only value where x !== x is true