Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

Unary plus

Unary plus (+) is the one-operand form of the plus operator. It leaves numbers unchanged and converts non-number operands to numbers, like Number(...).

How it works

Unary plus is the prefix + applied to one value. It leaves numbers unchanged and converts other values to numbers, using the same conversion behavior as Number(...); this makes it useful when numeric input arrives as text.

Syntax

+operand

Parameters

NameTypeDescription
operandany JavaScript valueThe single value to convert to a number.

Returns

The operand converted to a number; an existing number is unchanged.

Key points

  • Unary plus is classified as a unary operator because it works with one operand.
  • The same + token represents either addition or unary conversion depending on whether it has one or two operands.
  • Non-number operands are coerced to numeric values.
  • The boolean true converts to the number 1.
  • Unary plus has higher precedence than binary addition, so conversion happens first.

Common mistakes

  • It does not change an operand that is already a number.
  • Unary plus is concise, but it is not a different numeric-conversion algorithm from Number(...).
  • In an expression containing both forms of +, unary conversion happens before addition because unary plus has higher precedence.

Example: Convert values before addition

const first = "10";
const second = "2";

const total = +first + +second;
console.log(total); // 12
console.log(+true);   // 1
console.log(+"");      // 0

The unary plus converts each string operand to a number before the binary plus adds them.

When to use it

Numeric input conversion

Convert text from a form, prompt, query parameter, or other input source before arithmetic.

Explicit coercion

Force values such as booleans or empty strings through JavaScript’s numeric conversion rules.

Safe addition of numeric strings

Convert operands before a binary + expression so numeric strings are added rather than concatenated.

Interview questions

QWhat does unary plus do?

Unary plus is the prefix + operator with one operand. It returns numeric operands unchanged and converts non-numeric operands to numbers, like Number(...).

Follow-up: What happens with +true and +""? They become 1 and 0, respectively, because both values undergo numeric conversion.

QWhy use unary plus with input values?

Use +value when a value should be coerced to a number, such as text returned from input. For example, +"12" produces the number 12, whereas leaving the text unchanged can make binary + concatenate strings.

Follow-up: Why does +a + +b work for numeric strings? Each unary plus converts its operand before the binary addition runs.

QHow is unary plus different from binary plus?

JavaScript distinguishes unary plus from binary plus by the number of operands. Unary plus has one operand and converts it; binary plus has two operands and performs addition or string concatenation according to the operands.

Follow-up: Which runs first in +a + +b? Both unary operators run before the binary addition because unary plus has higher precedence.

  • Number()
  • binary plus (+)
  • unary minus (-)
  • operator precedence

Source: operatorsBasic operators, maths - The Modern JavaScript Tutorial. Checked 2026-10-15.