JS Built-ins
← Math45 / 215
Mathabsintermediate

Math.abs() with NaN and Infinity

πŸ“– Usage Example
// Get the absolute value of a number
Math.abs(-7)   // β†’ 7
Math.abs(3.5)  // β†’ 3.5

Use Math.abs() when you need the magnitude of a number regardless of its sign.

Math.abs(x)

Math.abs(NaN) returns NaN and Math.abs(Infinity) returns Infinity.

Challenge: Understand how Math.abs() handles special numeric values.

πŸ’‘ Hints (2)
  • β€’ NaN is the only value not equal to itself
  • β€’ Math.abs() of Β±Infinity returns positive Infinity