The addition operator + adds two numbers together.
When adding numeric values, be aware of some important subtleties.
First, integer addition is straightforward:
print(5 + 6) //integer addition (11)
If you add a double to an integer, the result is a double:
print(5.1 + 6) //double addition (11.1)
If you add two doubles, the result is a double:
print(5.1 + 6.2) //double addition (11.3)
The addition operator can be used to concatenate two strings:
//string concatenation (Hello, World) print("Hello, " + "World")
The addition operator can be used as a unary plus operator which operates on only one operand:
var num1 = 8 var anotherNum1 = +num1 //anotherNum1 is 8 var num2 = -9 var anotherNum2 = +num2 //anotherNum2 is -9