What is the variant type?

Many roblox functions return the Variant type, but I still don’t know what it means exactly. Intuitively I think it’s any type, but when I saw the definition of the assert function I was confused because it says it returns everything it passed.
I searched the site and the forum but could not find your exact definition.

1 Like

You’re correct: Variant denotes any type. In the case of assert, the function will verify that the first argument is a truthy value (not false or nil) and return that value; otherwise, it will throw an error with an optional second argument for context.

-- Valid input
local Input = 5
Input = assert(type(Input) == "number" and Input, "number expected, got " .. type(Input))
print(Input) --> 5

-- Invalid input
local Input = "clam chowder"
Input = assert(type(Input) == "number" and Input, "number expected, got " .. type(Input)) --> number expected, got string
2 Likes