-
Notifications
You must be signed in to change notification settings - Fork 8
2.7 Operators
Many operators are known to us from school. They are addition +
, a multiplication *
, a subtraction -
and so on.
In this chapter we concentrate on aspects that are not covered by school arithmetic.
Before we move on, let’s grasp the common terminology.
-
An operand – is what operators are applied to. For instance in multiplication
5 * 2
there are two operands: the left operand is5
, and the right operand is2
. Sometimes people say “arguments” instead of “operands”. -
An operator is unary if it has a single operand. For example, the unary negation
-
reverses the sign of the number:let x = 1; x = -x; alert( x ); // -1, unary negation was applied
-
An operator is binary if it has two operands. The same minus exists in the binary form as well:
let x = 1, y = 3; alert( y - x ); // 2, binary minus subtracts values
Formally, we’re talking about two different operators here: the unary negation (single operand, reverses the sign) and the binary subtraction (two operands, subtracts).