JS Built-ins
← Math44 / 215
Mathabsintermediate

Negative Zero Behavior

πŸ“– 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)

JavaScript has a special -0 value. Math.abs(-0) returns positive 0.

Challenge: Understand how Math.abs() handles negative zero.

πŸ’‘ Hints (2)
  • β€’ -0 is a valid IEEE 754 value in JavaScript
  • β€’ Object.is() distinguishes -0 from 0, but Math.abs(-0) removes the sign