Learning TypeScript 2.x
上QQ阅读APP看书,第一时间看更新

Assignment operators

TypeScript supports the following assignment operators:

Operator

Description

Example

=

Assigns the values from the right-side operands to the left-side operand.

C = A + B will assign the value of A + B into C

+=

Adds the right operand to the left operand and assigns the result to the left operand.

C += A is equivalent to C = C + A

-=

Substracts the right operand from the left operand and assigns the result to the left operand.

C -= A is equivalent to C = C - A

*=

Multiplies the right operand by the left operand and assigns the result to the left operand.

C *= A is equivalent to C = C * A

/=

Divides the left operand by the right operand and assigns the result to the left operand.

C /= A is equivalent to C = C / A

%=

Calculates the modulus using two operands and assigns the result to the left operand.

C %= A is equivalent to C = C % A