Menu
Coddy logo textTech

Functions Returning Nothing

Part of the Introduction To Luau section of Coddy's Lua journey — lesson 24 of 73.

Plenty of functions don't compute a value — they do something: print a message, update a table, save state. In Luau you can annotate that a function returns nothing with the empty return type ():

function logMessage(message: string): ()
    print(message)
end

local counter = 0
function incrementCounter(): ()
    counter += 1
end

If you've seen TypeScript, () plays the role of void — but the Luau spelling is a pair of empty parentheses, literally "zero return values".

The annotation is optional: leave it off and Luau infers that the function returns nothing. Writing : () explicitly documents your intent — anyone reading the signature knows this function is called for its side effects, not its result.

At runtime nothing changes (as usual): a function without a return value simply produces nil if you try to capture its result — same as plain Lua.

challenge icon

Challenge

Easy

Create a function named displayWelcome that takes userName: string and has an explicit return type of (). It should print: "Welcome to our application, [userName]!"

Create a function named logError that takes errorMessage: string with return type (). It should print: "ERROR: [errorMessage]"

Create a function named processData that takes no parameters, return type (). It should print "Processing data..." and then "Data processing complete." on the next line.

Call them in this order:

  1. displayWelcome("Alice")
  2. processData()
  3. logError("Invalid input detected")
  4. displayWelcome("Bob")

Try it yourself

-- Write code here
-- displayWelcome(userName: string): ()
-- logError(errorMessage: string): ()
-- processData(): ()
-- then call: displayWelcome("Alice"), processData(),
-- logError("Invalid input detected"), displayWelcome("Bob")
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Introduction To Luau