08.12.2022 Views

javascript_tutorial

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

+= (Add and Assignment)

2

It adds the right operand to the left operand and assigns the result to the

left operand.

Ex: C += A is equivalent to C = C + A

-= (Subtract and Assignment)

3

It subtracts the right operand from the left operand and assigns the result

to the left operand.

Ex: C -= A is equivalent to C = C - A

*= (Multiply and Assignment)

4

It multiplies the right operand with the left operand and assigns the result

to the left operand.

Ex: C *= A is equivalent to C = C * A

/= (Divide and Assignment)

5

It divides the left operand with the right operand and assigns the result to

the left operand.

Ex: C /= A is equivalent to C = C / A

%= (Modules and Assignment)

6

It takes modulus using two operands and assigns the result to the left

operand.

Ex: C %= A is equivalent to C = C % A

Note: Same logic applies to Bitwise operators, so they will become <<=, >>=, >>=,

&=, |= and ^=.

Example

Try the following code to implement assignment operator in JavaScript.

42

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!