JavaScript Logic in After Effects Expressions: Variables, if Statements, Arrays, linear, ease and valueAtTime

Adobe After Effects 70 min min read Updated: Nov 17, 2026 Advanced
JavaScript Logic in After Effects Expressions: Variables, if Statements, Arrays, linear, ease and valueAtTime
Advanced Topic 3 of 3

Variables

A variable stores a value. Use var or let. Example: let amp = 40;

Arrays

Position is an array of two numbers: [x, y]. You can change one part: [value[0] + 100, value[1]] moves 100 pixels right.

if Statements

An if makes a choice. Example: if the time is over 2 seconds, change the opacity.

javascript if (time > 2) { 100; } else { 0; }

linear and ease

linear(t, tMin, tMax, value1, value2) maps a time range to a value range. ease() does the same with smooth ends.

javascript // Fade in from second 1 to second 3 linear(time, 1, 3, 0, 100) // Smooth version ease(time, 1, 3, 0, 100)
python def linear(t, t_min, t_max, v1, v2): if t <= t_min: return v1 if t >= t_max: return v2 return v1 + (v2 - v1) * (t - t_min) / (t_max - t_min) def ease(t, t_min, t_max, v1, v2): if t <= t_min: return v1 if t >= t_max: return v2 x = (t - t_min) / (t_max - t_min) x = x * x * (3 - 2 * x) return v1 + (v2 - v1) * x for t in [0, 1, 1.5, 2, 2.5, 3, 4]: print("time", t, "linear:", round(linear(t, 1, 3, 0, 100), 1), "ease:", round(ease(t, 1, 3, 0, 100), 1))
Result

time 0 linear: 0 ease: 0 | time 1 linear: 0 ease: 0 | time 1.5 linear: 25.0 ease: 15.6 | time 2 linear: 50.0 ease: 50.0 | time 2.5 linear: 75.0 ease: 84.4 | time 3 linear: 100 ease: 100 | time 4 linear: 100 ease: 100

Both start at 0 and end at 100. At time 1.5 the ease value is lower than the linear value, because ease starts slowly.

valueAtTime and index

  • thisComp.layer(index - 1).transform.position.valueAtTime(time - 0.1) makes a layer follow the layer above it with a 0.1 second delay
  • index is the layer number, so you can offset animation per layer using index * 0.1
Learn from others Read expressions on animation presets and Adobe's expression reference to see how experienced users write them.

Practice

  1. Fade a layer in with linear between seconds 1 and 3
  2. Make a chain of 8 circles follow each other with valueAtTime
  3. Use if to change a color after 5 seconds
  4. Rewrite a keyframe animation as an ease expression

Conclusion

Variables, arrays, if, linear, ease and valueAtTime give expressions real power.

Quick Summary: Variables; arrays; if; linear and ease; valueAtTime; index.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators