Introducing Operators

Expressions and conditions combine data using operators. Operators must work on something to be able to operate. They can work on one piece of data, which makes them unary operators. They can work on two pieces of data, which makes them binary operators, or they can work on three pieces of data, which makes them ternary operators.

Let's look at some of the more common operators.

Arithmetic Operators

These operators are the familiar mathematical ones. They are

  • Plus (+)

    1 + 3 = 4
    
  • Minus (-)

    2 - 1 = 1
    
  • Division (/)

    4 / 2 = 2
    
  • Multiplication (*)

    2 * 2 = 4
    
  • Modulus (%)

    9 % 5 = 4
    

NOTE

All these operators are binary.

The only arithmetic operator that might need further explanation is the modulus operator. This operator, also called ...

Get JavaScript™ 1.5 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.