nil

Contents

nil#

nil is the absence of a value. Reading an undeclared local, an unset global, or a missing table field returns nil. Writing nil to a table field removes it.

Uninitialised local is nil.

local a              -- a is nil

Assigning nil removes the entry from a table.

t.k = nil

nil is falsy. Use x == nil (not not x) when the operator needs to distinguish “absent” from false.

if x == nil then handle_absent() end

References#

  • boolean for the truthiness rules nil participates in.

  • Operators for and / or short-circuit behaviour.