How do you use the new compound assignment operators?

You use them the same you would use, say these:

local a = 0
a = a + 1

local b = 11
a = a - 1

You can shorten these to

a += 1
b -= 1

and a will be incremented by 1, b decremented by 1

Luau also introduces *=, /=, %=, ^=, ..= which are multiplication, division, modulus, exponentation, and concatenation respectively.

7 Likes