# Comparison

(Redirected from ==)

Comparison operators are used to compare two variables, typically numbers.

## Operators

The Lua core is capable of the following comparison operators:

Less than: < Compares the left variable to the right variable. Returns true if the left is less than the right, otherwise returns false.

Greater than: > Compares the left variable to the right variable. Returns true if the left is greater than the right, otherwise returns false

Less than or equals: <= Compares the left variable to the right variable. Returns false if the left is greater than the right, otherwise returns true. This is logically the exact opposite of the Greater than operator.

Greater than or equals: >= Compares the left variable to the right variable. Returns false if the left is less than the right, otherwise returns true. This is logically the exact opposite of the Less than operator.

Equals: == Compares the left variable to the right variable. Returns true if the two variables are equal1, or false if they are not.

Not Equals: ~= Compares the left variable to the right variable. Returns false if the two variables are equal (a few exceptions, see special cases), or true if they are not. This is logically the exact opposite of the Equals operator.

## Special cases

- NaN (Not a Number) is the only Lua value that is not equal to itself.

- Tables will compare differently than one might expect. For example, {3} == {3} is false because the two tables have different pointers. However, local tbl = {3}; print( tbl == tbl ) will display true as the pointer is the same.