Lua Data Types Overview
Explore nil, boolean, number, string, table, function, and userdata types.
Welcome to Lua
Lua is a lightweight, fast, and embeddable scripting language used in game engines, web servers, and embedded systems. Before writing any real programs, you need to understand how Lua represents data.
Lua has 8 basic types: nil, boolean, number, string, table, function, userdata, and thread. Every value in Lua belongs to exactly one of these types.
-- Check the type of any value with type()
print(type(42)) -- number
print(type("hello")) -- string
print(type(true)) -- boolean
print(type(nil)) -- nilnil: The Absence of Value
nil is Lua's way of representing nothing or no value. It is the only value of its type. Variables that have never been assigned hold nil automatically.
Assigning nil to a global variable effectively deletes it. In tables, setting a key to nil removes that entry entirely.
-- Unassigned variables are nil
print(x) -- nil
x = 10
print(x) -- 10
x = nil
print(x) -- nil (variable is gone)All lessons in this course
- Lua Data Types Overview
- Declaring Variables in Lua
- Arithmetic and Relational Operators
- Type Coercion and Conversion