JavaScript +x Unary plus Operator
The unary plus operator (+) placed before a value converts it to a number. It's a short alternative to Number().
Description
The unary plus operator +, placed before a single operand, converts it to a number, just like Number(value). +'42' is 42, +true is 1, +'' is 0 and +'abc' is NaN. It can't convert BigInts and throws a TypeError if you try. Number() is more readable when the intent isn't obvious.
Unary plus has a high precedence, so in an expression like +a + +b each operand is converted before they're added together, which is a quick way to add two numeric strings. Applied to a Date, it returns the timestamp, +new Date(), although Date.now() is clearer for the current time.
Its conversion rules are strict: the whole string must be a valid number (with surrounding white space ignored), so +'12px' is NaN. Use parseInt() or parseFloat() when a string starts with a number followed by other text, such as CSS values.
Properties
- Operator
+x- Category
- Unary
- Precedence
- 14 (1 is lowest, 18 is highest)
- Associativity
- right-to-left
Syntax
+xExample
Browser Support
The following information will show you the current browser support for the +x operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





