JavaScript Unary Plus and Negation Operators

JavaScript provides unary plus (+) and unary negation (-) operators to perform arithmetic evaluation and type coercion on a single operand. Both operators convert their operand into a numeric primitive using the abstract ToNumber operation defined in the ECMAScript specification. While the unary plus returns the converted numeric value as-is, the unary negation converts the operand to a number and then reverses its sign.

The Unary Plus Operator (+)

The unary plus operator precedes its operand and evaluates to the operand’s numeric representation. It serves as the fastest and most concise way to explicitly cast a value to a number.

+42;          // 42
+"100";       // 100
+"";          // 0
+true;        // 1
+false;       // 0
+null;        // 0
+undefined;   // NaN
+"text";      // NaN

The Unary Negation Operator (-)

The unary negation operator precedes its operand, converts the operand into a number if necessary, and then negates the resulting value.

-42;          // -42
-"50";        // -50
-true;        // -1
-false;       // -0
-null;        // -0
-undefined;   // NaN
-10n;         // -10n

Evaluating Objects and Non-Primitive Values

When either operator encounters an object, JavaScript first converts the object into a primitive value using the internal ToPrimitive algorithm with a number hint.

  1. Method Resolution: The engine checks for a [Symbol.toPrimitive]('number') method. If absent, it attempts to call the object’s valueOf() method, followed by toString().
  2. Numeric Coercion: Once a primitive value (string, boolean, or number) is returned, the engine applies the standard ToNumber coercion followed by the operator’s logic.
// Empty array converts to empty string "", then to 0
+[];          // 0
-[];          // -0

// Single-element array converts to "5", then to 5
+[5];         // 5
-[5];         // -5

// Multi-element array converts to "1,2", which is not a valid number
+[1, 2];      // NaN

// Plain object converts to "[object Object]", which is not a valid number
+{};          // NaN

// Date objects convert to their millisecond Unix timestamp via valueOf()
+new Date("2026-01-01"); // 1767225600000