/

HTML / CSS / JavaScript Tutorial

JavaScript Operator: plus

[this page | pdf | back links]

In JavaScript, the + operator has three possible meanings:

 

Arithmetic operator (binary)

 

Addition, e.g. if x is 8 then y = x + 2 results in y becoming 10

 

Arithmetic operator (unary)

 

Plus sign, e.g. if x is 8 then then +x represents -8

 

String operator (binary)

 

Concatenation, e.g. if x is "a" then y = x + "b" results in y becoming "ab"

 

Further comments

 

If an expression involves ‘adding’ a string to a number then the number is coerced to a string and string concatenation is applied.

 


NAVIGATION LINKS
Contents | Prev | Next | JavaScript Operators


Desktop view | Switch to Mobile