10 min

A boolean is a very simple data type with a value of either true or false. Booleans are most commonly used with Articles/Conditional Statements in Lua|conditional statements, for instance:

Lua Evaluation

In Lua, if a value is not false or nil, it’s considered “true” when used in a conditional statement. The code below prints out only the values which Lua interprets as true:


Based on the evaluation rules above, conditional statements with Lua /articles/Operators|operators work as follows:


The and operator returns the first argument if it’s false or nil, otherwise it returns the second argument.


The or operator operates on two values. If the first value is neither false nor nil, the or operator returns the first value. If the first value is false or nil, then it returns the second value. For instance:

This printed 1 because x doesn’t exist and is therefore nil. Effectively, the or operator let us choose 1 in favor of nil.

This also printed 1 because, although x exists, its value is false. If x had been true, the or operator would have chosen x in favor of 1.


The not operator returns true if the argument is false or nil, otherwise it returns false.

  • lua
  • value
  • boolean