More on JavaScript Operators

Read this article to learn more about using operators in JavaScript. We will not use all of them in this introductory course. However, this is a condensed reference that contains tables of all operator categories. JavaScript categorizes operators by the task (such as arithmetic, comparison, or assignment). Operators execute in a particular order. This is called operator precedence and tells JavaScript which part to evaluate first, second, third, and so on. This is an important concept. 

For example, consider how a program calculates a price using arithmetic operators:

Multiplication first the result is: $18 = 4 + 2 * 7 ( 2 * 7 = 14 + 4)
Calculate left to right the result is: $42 = 4 + 2 * 7 (4+ 2 = 6 * 7)

Operators

JavaScript has the following types of operators. This section describes the operators and contains information about operator precedence.

  • Assignment operators
  • Comparison operators
  • Arithmetic operators
  • Bitwise operators
  • Logical operators
  • String operators
  • Conditional (ternary) operator
  • Comma operator
  • Unary operators
  • Relational operators

JavaScript has both binary and unary operators, and one special ternary operator, the conditional operator. A binary operator requires two operands, one before the operator and one after the operator:

operand1 operator operand2

For example, 3+4 or x*y.

A unary operator requires a single operand, either before or after the operator:

operator operand

or

operand operator

For example, x++ or ++x.


Source: Mozilla, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
Creative Commons License This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.