Add Operator
All programming languages support the basic arithmetic operations of addition, subtraction, multiplication and division of numbers. The addition operator is also used to add, or concatentate, two strings together.
Examples
Adding a Few Things
Combining different values with addition
// Add numbers, add strings,
// and add variables
// containing numbers.
write(3+5);
write("3"+"5");
var x=3;
var y=5;
write(x+y);
Syntax
value1 + value2;
Parameters
Name | Type | Required? | Description |
---|---|---|---|
value1 | Any | First value to be added or concatenated | |
value2 | Any | Second value to be added or concatenated |
Returns
Tips
- Operator precedence is the same as standard arithmetic - Expressions within a parentheses have the highest precedence, then multiplcation and division, then addition and subtraction.
- If either one of the operands are a string it treats the addition as string concatentation.
Found a bug in the documentation? Let us know at support@code.org.