Operators

Contact Us or call 1-877-932-8228
Operators

Operators

Basic Operators

Basic operators allow you to manipulate values.

Addition and Subtraction

2 + 3;
2 - 3;

Concatenation

var foo = 'hello';
var bar = 'world';

console.log(foo + ' ' + bar);  // 'hello world'

Multiplication and Division

2 * 3;
2 / 3;

Incrementing and Decrementing

var i = 1;

var j = ++i;   // pre-increment:  j equals 2; i equals 2
var k = i++;   // post-increment: k equals 2; i equals 3

Combination Operators

var x = 0;
x += 3;         // same as x = x + 3;
x -= 4;         // same as x = x - 4;
x *= 5;         // same as x = x * 5;
x /= 6;         // same as x = x / 6;

var y = "Hello";
y += " World";  // y is now "Hello World"

Parentheses Affect Precedence:

2 * 3 + 5;    // returns 11; multiplication happens first:
2 * (3 + 5);  // returns 16; addition in ( ) happens first
Next