Skip to content

unary plus and negation (+, -)

In JavaScript, the unary plus and negation operators (+, -) take one operand, written after the symbol, and convert it to a numeric value. Unary plus returns that value as is, and unary negation returns it with the opposite sign.

For any value but a bigint, the conversion follows the same rules as Number(). A numeric string such as "42" becomes 42, true becomes 1, null and "" become 0, and a string that isn’t a number becomes NaN. Unary negation also accepts a bigint and returns a negated bigint, but unary plus throws a TypeError for one.

JavaScript Unary Plus and Negation Syntax

Each operator goes directly before the expression it converts:

Language: JavaScript Syntax
+<operand>
-<operand>

The two operators give these results for the string operand "7":

Operator Name Example Result
+ Unary plus +"7" 7
- Unary negation -"7" -7

Both bind tighter than the binary arithmetic operators, so +"3" + 4 evaluates to 7.

JavaScript Unary Plus and Negation Examples

Say a form field holds a width as the string "120", and the layout code adds a margin of 30. Binary + would join the two as text, but a unary + in front converts the input first:

Language: JavaScript
> const width = "120";
undefined

> width + 30
'12030'
> +width + 30
150

> +"12px"
NaN
> +""
0

Unary plus parses the whole string, so a trailing unit gives NaN. An empty field becomes 0 instead of signaling missing input.

Say a ledger stores a balance in cents as a bigint and shows debits as negative values. Unary negation keeps the bigint type, while unary plus can’t convert it:

Language: JavaScript
> const balance = 25000n;
undefined

> -balance
-25000n
> +balance
Uncaught TypeError: Cannot convert a BigInt value to a number

> Number(balance)
25000

Calling Number() converts a bigint explicitly, though it can lose precision for integers whose magnitude exceeds Number.MAX_SAFE_INTEGER.

JavaScript Unary Plus and Negation Gotchas

  • Negating 0 returns -0, which === treats as equal to 0, while Object.is(-0, 0) returns false.
  • Two minus signs with no space between them form the decrement operator (--), so - -count negates twice while --count subtracts one from count.
  • A unary operator can’t sit directly before the base of **, so -2 ** 2 is a SyntaxError, while (-2) ** 2 evaluates to 4.

JavaScript Unary Plus and Negation Use Cases

  • Converting form input, query parameters, and other strings to numbers
  • Turning a Date object into a millisecond timestamp with +date
  • Flipping the sign of a number or a bigint
  • Turning Booleans into 1 and 0 for counting
A developer holds up a €1,303.20 invoice beside a clay machine with a CENTS coin sorter, a long BigInt odometer under a euro money bag, an isFinite() gauge and a NumberFormat receipt printer.

Course

JavaScript Number Precision, BigInt, and Formatting for Pythonistas

Port a coffee roastery's month-end invoice script from Python to JavaScript, and learn to keep money and big IDs exact, catch Infinity and NaN, and format numbers like Python.

intermediate js py

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 12, 2026