skip to Main Content

After Effects Expressions & JavaScript

semicolon

You probably noticed that most lines in the various blocks of code on this website end in a semicolon (if you ignore the comments). Basically the semicolon separates statements in the code, similar to periods in a sentence, so After Effects doesn’t get confused by a single, long run-on sentence. While writing the code as a single line does require the use of a semicolon between statements, that’s not always true when you place line breaks between them.

R
=
12
R
//JavaScript is fine with this formatting, but most people aren't.

So what’s the deal, you may be asking, when do I know when I have to use a semicolon? I’ll get to that, but first do know that many people who code place a semicolon at the end of a line no matter what. I’m one of those people, so that’s the way I write expressions. If the line ends in an open or closed curly bracket, or it’s a single line of code, or it’s the last line of code, I’ll usually leave off the semicolon. This is acceptable practice if you would like to go this route.

However, there are also many people who add semicolons only when they are needed. With a couple of exceptions, the rule is: after a return, if the next character (remember, spaces are always ignored) cannot be interpreted as a continuation of the previous line, then JavaScript regards the return as a semicolon, so you don’t need to place one.

R=12
L=13
R
//No semicolon is required for lines 1-3. The line breaks are read like semicolons because the character that follows the return can't be interpreted as a continuation of the previous line.
//However
R=12;L=13;R
//Because line 6 contains several statements on one line, a semicolon is required to separate them.

If you’re interested in more detailed information about the use of the semicolon in JavaScript see “Understanding automatic semicolon Insertion in JavaScript” by Bradley Braithwaite, a software developer who works for the search engine duckduckgo.com.

Back To Top