NG.II · Angular 22 practice question
A developer implements an `effect` in a component to log the current value of a user status signal whenever it changes. What is guaranteed about the execution of this effect?
import { effect } from '@angular/core';
const status = signal('idle');
effect(() => {
console.log(`Status is: ${status()}`);
});
Check answer and explanation
Correct answer: The effect is guaranteed to run at least once upon initialization, and subsequently whenever any dependency signal changes.
Explanation
The correct statement is that the effect is guaranteed to run at least once upon initialization, and subsequently whenever any dependency signal changes. This accurately describes the inherent behavior of effects.
Common trap
The statement claiming the effect will only execute if the signal is explicitly updated via a setter function is incorrect because effects monitor signal reads, not solely setter invocations. Furthermore, the assertion that the effect will only run asynchronously if the change detection cycle is manually triggered is wrong, as effects execute asynchronously by default during the change detection process.
Source: Angular docs: Effects — Effects
Checked against the cited text on 2026-11-25.