That's the whole question lol.
Semicolons are usually optional and can be used to visually separate statements (ex on the same line). They are mandatory if you do something like this:
local myVar = 5 print("Hello") (myVar == 5 and print or warn)("This line will error because there is no semicolon")
Specifically, it will error with ambiguous syntax (function call x new statement) near '('
. Adding a semicolon after line 2 or at the start of line 3 fixes it:
local myVar = 5 print("Hello") ;(myVar == 5 and print or warn)("This message will be printed since myVar is 5")
Does this happen in practice? It can; though it's rare, sometimes it's nice to be able to specify which function you want to use (via the and or
"ternary") in the same line you use it.