Menu
CoddyTech

Number, String and Boolean

Part of the Introduction To Luau section of Coddy's Lua journey. Lesson 6 of 80.

Luau has three fundamental primitive types that form the building blocks of most programs: string, number and boolean. You've been using these values in Lua all along: Luau lets you declare them as types.

The string type is for text data:

local productName: string = "Laptop"

The number type handles all numeric values: integers and decimals alike, just as you know from Lua's single number type:

local price: number = 999.99

The boolean type represents true/false values, perfect for flags and conditions:

local inStock: boolean = true

Once annotated, each variable is held to its type: assign the string "500" to price and the type checker complains immediately. And remember: print(inStock) prints the word true, because booleans stringify to true/false.

challenge icon

Challenge

Easy

Describe a product with three typed variables.

  1. Declare local productName: string = "Gaming Mouse".
  2. Declare local price: number = 49.99 and local inStock: boolean = true.
  3. Print the three variables, one per line, in that order.

Press Run Code: the output shows Gaming Mouse, 49.99 and true.

Try it yourself

-- 1) declare productName, price and inStock with their types
-- 2) print all three, each on its own line

All lessons in Introduction To Luau

Practice on your own: Online Luau compiler