You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bunlong VAN edited this page Feb 15, 2018
·
5 revisions
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.
Terms: “unary”, “binary”, “operand”
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 is 5, and the right operand is 2. 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).