Menu

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 similarly.

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

Operators:

  • x + y (numbers) – adds x and y
  • x + y (strings) – joins the x and y strings
  • x - y – subtracts y from x
  • x * y – multiplies x and y
  • x / y – divides x by y
  • x % y – remainder of x / y
  • x++, ++x – adds one to x
  • x--, --x – subtracts one from x
  • -x – reverses the sign of x