boolean

Contents

boolean#

Only false and nil are falsy. Every other value, including 0, "", and the empty table {}, is truthy. The operator who comes from C or Python gets surprised by this exactly once.

0 is truthy.

if 0 then print("yes") end           -- prints

Empty string is truthy.

if "" then print("yes") end          -- prints

Empty table is truthy.

if {} then print("yes") end          -- prints

nil is falsy (so is false).

if nil then print("yes") end         -- silent

and and or short-circuit and return one of their operands, not a clean true / false. See Operators.

References#

  • nil for the only other falsy value.

  • Operators for and / or short-circuit and Lua’s ternary substitute.