Statement Completion Values
When there's multiple statements in your expression, it's important to know what value After Effects will use for the property once the code is evaluated.
For example in the expression:
const myPosition = [960, 540];myPosition * 2;[0, 0];const otherPosition = [500, 500];
The property will be set to
[0, 0], but why?
What is a statement?
These instructions include tasks such as "assign this value to this variable", "return this value from the function", or "throw this error".
A unit of code that produces (or results in) a value, such as:
- A value itself:
- A mathematical operation:
12 * 5
Expressions can be part of a statement, such as:
const aValue = 12 * 5;
Or as a statement itself:
12 * 5;
Expression statements are statements that contain only an expression.
Statements such as variable declarations (
const myVariable = 2;) have a completion value of
// Completion value: emptyconst myVariable = 2;// Completion value: emptylet someString = "hello";
While expression statements have a completion value that is the result of the expression.
[960, 540];// Completion value: [960, 540]Math.random();// Completion value: 0.3("Hello");// Completion value: "Hello"
The result of an expression will be the last completion value that isn't
This means that the value of a property will almost always be the result of the last expression statement.
Some other statements, such as if statements with falsy conditions, have a completion value of
So if we consider the completion values of each statement in our earlier expression:
const myPosition = [960, 540]; // empty// Expression statementmyPosition * 2; // [1920, 1080]// Expression statement[0, 0]; // [0, 0]const otherPosition = [500, 500]; // empty
You can see that
[0, 0] will be used as it's the last statement with a non-empty completion value.
Knowing which statement will set the value for your expression becomes important as you write longer, more complex expressions.