TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
- operator in JavaScript functions as both a binary subtraction operator and a unary negation operator. In both contexts, it performs implicit type coercion, forcing non-numeric operands to resolve to primitive numbers (or BigInts) before evaluating the mathematical expression.
Binary Subtraction
As a binary operator,- computes the difference between two operands.
- Both operands are evaluated.
- JavaScript applies the abstract
ToNumericoperation to both operands. - If the operands are of different numeric types (e.g.,
NumberandBigInt), aTypeErroris thrown. - The right operand is subtracted from the left operand based on their resolved numeric type:
- If the operands are of type
Number, the operation is performed according to IEEE 754 double-precision floating-point arithmetic. - If the operands are of type
BigInt, the operation is performed using arbitrary-precision mathematical integer arithmetic.
- If the operands are of type
+ operator, which is overloaded for string concatenation, the binary - operator strictly enforces numeric evaluation.
Unary Negation
As a unary operator,- precedes a single operand. It coerces the operand to a numeric value and inverts its algebraic sign.
- The operand is evaluated.
- The abstract
ToNumericoperation is applied. - If the resulting value is
NaN, the result remainsNaN. - Otherwise, the sign of the numeric value is inverted.
Object Coercion (ToPrimitive)
When the- operator is applied to an Object, JavaScript attempts to resolve a primitive value by invoking the object’s internal [[ToPrimitive]] method, prioritizing the valueOf() method before falling back to toString().
BigInt Mechanics
The- operator fully supports BigInt primitives for both binary subtraction and unary negation. However, JavaScript prohibits mixing BigInt and Number types to prevent precision loss.
IEEE 754 Edge Cases
Because JavaScriptNumber types are floating-point values, the - operator adheres to specific rules regarding Infinity, NaN, and signed zeros (+0 and -0).
Master JavaScript with Deep Grasping Methodology!Learn More





