What does a semicolon do when it’s been added?
Please tell me the details
We cannot help with that much information. What are you adding to?
something like this
local module = {
number = 10;
}
The first primary use of a semicolon is to have the ability to create multiple statements in one line. Optionally, the semicolon is used in tables and is an alternate separator to ,
.
-- multiple statements
local a, b = 1, 2; print(a, b)
-- which is the same as
local a, b = 1, 2
print(a, b)
-- table separator
local t = {
{"haha", 1}; 2; 3;
}
Additionally, it seems that you can make your code worse by adding the ;
in the end of each line. Please don’t hurt me for this.
It’s a requirement in some languages and even some scenarios in Lua, so wouldn’t say it makes your code worse at all. Encountered the need for semicolon while debugging a Promise executor the other day.
local foobar = true
Promise.new(function (resolve, reject)
print("Promise acting")
;(foobar and resolve or reject)()
end)
Not even true? You don’t need it for that.
Depends which language you are talking about in javascript a semicolon is put at the end of code in lua it is as @Operatik said