Skip to content

Assignment Operators

Assignment operators assign a value to a variable. The basic assignment is =. Compound assignment operators combine an arithmetic or bitwise operation with assignment, such as +=, -=, *=, /=, %=, and **=.

let x = 10; // assignment
x += 5; // x = x + 5 -> 15
x -= 3; // x = x - 3 -> 12
x *= 2; // x = x * 2 -> 24
x /= 4; // x = x / 4 -> 6
x %= 4; // x = x % 4 -> 2
x **= 3; // x = x ** 3 -> 8