Expressions are small pieces of JavaScript attached to a property. They replace stacks of keyframes with one line, and the eight below cover most of what you will ever need. To add one, hold Alt (Option on a Mac) and click the property's stopwatch, then paste the code into the field that opens in the timeline.

One setting first: open File › Project Settings › Expressions and make sure the engine is JavaScript. Everything here works in both engines, but JavaScript runs much faster.

1. wiggle: organic movement

Random, smooth movement around the current value. The first number is how many times per second, the second is how far.

wiggle(2, 30)

On Position that is two moves per second, up to 30 pixels. To wiggle only the vertical axis, keep the original X and take Y from the wiggle:

w = wiggle(2, 30);
    [value[0], w[1]]

Put the two numbers on sliders (Effect › Expression Controls › Slider Control) and you can keyframe the intensity: wiggle(effect("Frequency")("Slider"), effect("Amplitude")("Slider")).

2. loopOut: repeat keyframes forever

loopOut("cycle")

Repeats the keyframes after the last one, forever. "pingpong" plays them forward then backward, "offset" keeps adding the difference each loop (good for a counter or a rolling wheel), and "continue" keeps moving at the final speed without repeating. loopIn() does the same before the first keyframe.

3. time: constant motion with no keyframes

time * 360

On Rotation, one full turn per second, forever. Negative numbers turn the other way. Use the same idea on Position ([value[0] + time * 200, value[1]]) for an endless scroll.

4. linear: map one range to another

linear(input, inMin, inMax, outMin, outMax)

Takes an input between two values and turns it into an output between two others. The classic use is audio: run Animation › Keyframe Assistant › Convert Audio to Keyframes, then on a layer's Scale write

amp = thisComp.layer("Audio Amplitude").effect("Both Channels")("Slider");
    s = linear(amp, 0, 20, 100, 130);
    [s, s]

Quiet parts sit at 100%, loud peaks reach 130%. ease() takes the same arguments and adds a smooth curve.

5. valueAtTime: a delayed follower

thisComp.layer(index - 1).transform.position.valueAtTime(time - 0.1)

On Position, the layer copies the layer above it with a tenth of a second delay. Duplicate the layer five times and you have a trail that follows the leader with no extra keyframes. index - 1 always means "the layer directly above", so the duplicates chain automatically.

6. Inertial bounce: overshoot after the last keyframe

The expression every motion designer ends up copying. It is by Dan Ebberts, and it adds a decaying bounce after the final keyframe of any property, so a logo lands with weight instead of stopping dead.

amp = 0.1;
    freq = 2.0;
    decay = 2.0;

    n = 0;
    if (numKeys > 0) {
      n = nearestKey(time).index;
      if (key(n).time > time) n--;
    }
    t = (n == 0) ? 0 : time - key(n).time;

    if (n > 0 && t < 1) {
      v = velocityAtTime(key(n).time - thisComp.frameDuration / 10);
      value + v * amp * Math.sin(freq * t * 2 * Math.PI) / Math.exp(decay * t);
    } else {
      value;
    }

Raise amp for a bigger overshoot, freq for more bounces, decay to settle faster. It works on Scale, Position, Rotation, anything with keyframes.

7. A counter with thousands separators

Add a Slider Control to a text layer, then put this on Source Text:

n = Math.round(effect("Slider Control")("Slider"));
    n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")

Keyframe the slider from 0 to 25000 and the text counts up as 25,000. Prefix a currency sign with "$" + .... For decimals, use n.toFixed(2) instead of Math.round.

8. sourceRectAtTime: a box that fits the text

Make a shape layer with a rectangle, give it the same Position as your text layer, and put this on the rectangle path's Size:

t = thisComp.layer("Title");
    r = t.sourceRectAtTime(time, false);
    pad = 40;
    [r.width + pad, r.height + pad]

And this on the rectangle path's Position, so the box stays centered on the text whatever its alignment:

t = thisComp.layer("Title");
    r = t.sourceRectAtTime(time, false);
    [r.left + r.width / 2, r.top + r.height / 2]

Now retype the title and the background follows. Lower thirds, captions and buttons all come down to this one pair of expressions.

Keep them

Select the property with the expression and choose Animation › Save Animation Preset. It lands in Effects & Presets under * Animation Presets, ready to drop on any layer in any project.

aep motion templates are built on expressions like these. Counters, bounces and auto-sized boxes come wired up, so you move a slider instead of pasting code. To see how a template works, press EE on its layers after you add it.