Hi, what’s the purpose of the | symbol in Luau? I’ve seen it be used before as a separator between the class of a function’s variables, but I’d like to know what advantages doing that has and what other uses the | symbol may have.
Example of how I’ve seen it used in the past:
local function test(v1:number | string)
print(v1)
end
Additionally, I have tried searching for this, however Google (and the dev forum) don’t seem to actually read the | symbol when searching. Either that or nobody has ever asked this before.
‘|’ defines multiple accepted types for a parameter. In your example, v1 can be either the number type or the string type. You can think of it as an “or” but for parameter types.