Why should I use a semicolon at the end of a line?


#1

Question

Why should I use a semicolon at the end of a line?

Answer

Whether you choose to add a semicolon or not to the end of a line of code is largely based on preference. It is encouraged to use semicolons explicitly in your code because they are automatically inserted at the end of each line upon execution for lines without them. For this reason, adding semicolons help make your code more predictable and easier to read, rather than having to guess where a line terminates. This difference only affects some uncommon cases, mainly where one statement spans multiple lines.