2.3 Assignment Operators
3️⃣

2.3 Assignment Operators

2.3 Assignment Operators

This is basically syntax sugar. It just makes your code look nicer and cleaner. You can accomplish everything here with the basic arithmetic operators and equal signs.

Assignment Operators

NameDescription
=
Assigns right operand value to the left operand.
+=
Sums up left and right operand values and assigns the result to the left operand.
-=
Subtract right operand value from left operand value and assign the result to the left operand.
*=
Multiply left and right operand values and assign the result to the left operand.
/=
Multiply left and right operand values and assign the result to the left operand.
%=
Get the modulus of the left operand divided by the right operand and assign the resulting modulus to the left operand.
let x = 5, y = 10, z = 15;

x = y;  // x would be 10

x += 1; // x would be 6

x -= 1; // x would be 4

x *= 5; // x would be 25

x /= 5; // x would be 1

x %= 2; // x would be 1

Practice

You can add practice problems here if you want. Follow the format below.

⚖️

Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.