← Back to the index page

Single vs double quotes in Lua

There is no difference in Lua language for quotes. You can use single or double quotes but try to be persistent within a codebase. Preferable to use double quotes because the single quote (' apostrophe) is much more often used inside the text than a double quote ". So no need to escape the sequence with \ backslash. Roblox Lua Style Guide and StyLua also recommend using double quotes.

Consider:

"5 o'clock" --- no need escape sequence
'Read "1984" book' -- double quotes inside single
"Read \"1984\" book" -- double quotes double single (escaped)

Another way to define string is to use blocks, in this case, no escape sequences are needed at all.

Consider:

[[ Start reading "1984" book as 5 o'clock ]]

Conclusion

Usually, code-style related discussions are a source of different holywars, provoked by purists and pedantists. This problem is always artificially created like this is a main problem in programming. Just choose the style of quotes that you like and use it.

Feedback

For feedback, please check the contacts section. Before writing, please specify where you came from and who you are. Sometimes spammers go insane. Thank you in advance for your understanding.

← Back to the index page