Skip to main content

When is effect called for the first time?

Suggest an edit

effect() is called immediately upon creation, once, to capture the initial state.

The order is as follows:

  1. You create effect(() => console.log(counter())).
  2. Angular immediately runs this code, printing the current value of counter().
  3. After that it is called every time counter changes.

Example:

ts
const counter = signal(0); effect(() => { console.log('counter:', counter()); });

Console output:

javascript
counter: 0 ← first call on creation counter: 1 ← after counter.set(1) counter: 2 ← after counter.set(2)

So the first run is simply initialization, so the effect immediately "knows" the current state.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

Suggest an edit