JS Built-ins
← Math184 / 215
Mathsignintermediate

Math.sign() β€” Negative Zero

πŸ“– Usage Example
// Returns -1, 0, or 1 based on sign
Math.sign(-5)   // β†’ -1
Math.sign(0)    // β†’ 0
Math.sign(3)    // β†’ 1

Use Math.sign() to determine whether a number is positive, negative, or zero.

Math.sign()

Returns the sign of a number, indicating whether it is positive, negative, or zero.

Challenge: Explore Math.sign(-0) which returns -0, distinguishable via Object.is.

πŸ’‘ Hints (1)
  • β€’ JavaScript has -0 as a distinct value; use Object.is to differentiate it from +0