JavaScript Infinity and Signed Zero: Numerical Edge Cases
Quick answer
Number includes positive and negative infinity and two signed zeros. These values have specified arithmetic behavior and can signal unbounded or special results.
How it works
Positive nonzero finite division by +0 yields Infinity; division by -0 yields -Infinity. Zero divided by zero yields NaN. Strict equality treats the two zeros as equal; Object.is distinguishes them. Number.isFinite rejects both infinities and NaN.
console.log(1/0, 1/(-0), 0/0);Expected output in Node.js:
Infinity -Infinity NaNSigned zero changes the sign of the infinite quotient.
console.log(0 === -0, Object.is(0,-0), Number.isFinite(-Infinity));Expected output in Node.js:
true false falseEquality methods differ for signed zeros.
Common mistakes
Check denominators and finite-result requirements explicitly. Do not assume division by zero throws an exception for Number arithmetic.
Practice
Predict division outputs for positive and negative zeros and compare with execution.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
JavaScript Infinity and Signed Zero: Numerical Edge Cases — Knowledge Check
Apply the taught concept and predict the output.
Which comparison distinguishes +0 from -0?
What is Infinity - Infinity?
Which predicate accepts finite fractional Numbers as well as integers but rejects infinities and NaN?
What is the exact console output in JavaScript Infinity and Signed Zero: Numerical Edge Cases example 1?
console.log(1/0, 1/(-0), 0/0);What is the exact console output in JavaScript Infinity and Signed Zero: Numerical Edge Cases example 2?
console.log(0 === -0, Object.is(0,-0), Number.isFinite(-Infinity));