skip to Main Content

After Effects Expressions & JavaScript

JavaScript comments

Adding comments in your code can help you remember or clarify what’s going on within all those symbols, values, and variables. Often, when writing expressions, comments aren’t needed, especially if the expression is short. But if you’ve spent time wrestling with how to make something work, that’s a sign you might want to add comments to help you remember how you achieved your goal. This can save you time, and from reinventing your method, should you need to return to edit your work. Comments are also helpful when sharing scripts with other animators.

There are two types of comment symbols:

Double forward-slash // 

Anything after two forward-slashes is ignored until you go to the next line. You can put the comments on their own line, or after your code.

//This is a comment on it's own line
R=123; //This is a comment after a statement

If you were going to put a comment between code (not a good idea), you would have to use the slash-asterisk comment (see next section).

Forward-slash asterisk followed by an asterisk forward-slash /*This is called a block comment.*/

Anything between a forward-slash asterisk and an asterisk forward-slash is ignored. These can span any number of lines and can be use to organize your comments.

/*This is a comment on a single line; a double forward-slash would do just as well here.*/

/*This multiline comment is ignored over several lines;
it's good for long comments that you don't want
to stretch great distances across the timeline or for lists.*/

Notice the blank line number 2 above. You can add an extra return to separate chunks of code to make it easier to read as well.

I use the comment symbols when I include notes in my written code samples (like on this page) so you can easily differentiate between what’s code and what’s commentary. This practice also makes it easy to copy and paste expressions that might be useful into your own projects because the code is formatted correctly, therefore it won’t generate an error.

R=/*I'm putting a comment here for some strange reason.*/32;R
Back To Top