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:
+<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:
> 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:
> 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
0returns-0, which===treats as equal to0, whileObject.is(-0, 0)returnsfalse. - Two minus signs with no space between them form the decrement operator (
--), so- -countnegates twice while--countsubtracts one fromcount. - A unary operator can’t sit directly before the base of
**, so-2 ** 2is aSyntaxError, while(-2) ** 2evaluates to4.
JavaScript Unary Plus and Negation Use Cases
- Converting form input, query parameters, and other strings to numbers
- Turning a
Dateobject into a millisecond timestamp with+date - Flipping the sign of a number or a
bigint - Turning Booleans into
1and0for counting
Related Resources
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.
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