Assignment Operators
Assignment Operators
Section titled “Assignment Operators”Introduction
Section titled “Introduction”Assignment operators assign values to variables. The basic = operator is extended by compound assignment operators that combine assignment with arithmetic.
Visual Explanation
Section titled “Visual Explanation”flowchart LR A["x = 5"] --> B["Basic assignment"] C["x += 3"] --> D["x = x + 3 → 8"] E["x -= 2"] --> F["x = x - 2 → 3"] G["x *= 4"] --> H["x = x * 4 → 20"] I["x /= 2"] --> J["x = x / 2 → 2.5"]Operators
Section titled “Operators”let x = 10;
x += 5; // x = x + 5 → 15x -= 3; // x = x - 3 → 12x *= 2; // x = x * 2 → 24x /= 4; // x = x / 4 → 6x %= 4; // x = x % 4 → 2x **= 3; // x = x ** 3 → 8Summary
Section titled “Summary”=assigns a value- Compound operators combine operation with assignment
- They make code concise and readable