Javascript Operators

Operators are the symbols which are used to work with variables. You are already familiar with simple arithmetic operators, plus and minus.

Important: While the x++ and ++x operators both add one to x, they are not identical. x++ increments x after the assignment and ++x before. If x is 4, y = x++ results in y is 4 and x is 5. y = ++x sets y = 5 and x = 5. The x– and –x operators work similar.

If you mix numeric and string values when adding to values together, the result is a string. HTMLcenter + 69 results in HTMLcenter69.



Operators

OPERATOR

x + y (numbers)

x + y (string)

x – y

x * y

x / y

x % y

x++, ++x

x–, –x

-x


WHAT IT DOES

Adds x + y

Adds x and y string

Subtracts y from x

Multiplies x and y

Divides x by y

Remainder of x / y

Adds one to x

Subtracts one from x

Reverses the sign of x