Operator Precedence


As we all learned in algebra, it is not only important to understand how operators work, but also understand the order in which operators are applied. The order in which operators are applied is governed by their precedence and their association.

Lua operators have the following precedence, ordered from highest to lowest priority, and association:

Group Operators Association
Exponentiation ^ Right
Unary Operators not # - ~ Left
Arithmetic * / % Left
Arithmetic + - Left
Concatenation .. Right
Bitwise & Left
Bitwise ~ Left
Bitwise | Left
Relational < > <= >= ~= == Left
Logical and Left
Logical or Left

As with algebra, parentheses can be used to override the order of precedence of an expression.