Variables and Data Types

Lua uses dynamic typing, meaning you don't need to explicitly declare variable types. You assign values directly:

name = "Alice"
age = 25
isStudent = true

Common data types in Lua include:

  • nil – represents a non-existent value
  • boolean – true or false
  • number – all numbers are floats (doubles)
  • string – sequences of characters
  • table – arrays, dictionaries, and objects
  • function – first-class functions
  • userdata and thread – advanced types

Use the type() function to check a variable's data type:

print(type(name))      -- string
print(type(age))       -- number
print(type(isStudent)) -- boolean
← PrevNext →