Add Operator

Category:Math

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

NameTypeRequired?Description
value1 Any First value to be added or concatenated
value2 Any Second value to be added or concatenated

Returns

The sum of two numbers or concatenation of two strings

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 documentation@code.org