What does interval() do?
interval() in RxJS creates an Observable that periodically emits numbers with a time delay.
Example:
ts
import { interval } from 'rxjs';
interval(1000).subscribe(x => console.log(x));This outputs:
javascript
0
1
2
3
...and so on, every secondEach number is a "tick". It starts at 0 and increases by 1.
Parameter:
interval(1000)means every 1000ms (1 second)- if you write
interval(500), it will tick twice a second
Where it's used:
- Timers
- Animations
- Status checks
- Periodic data loading
Conclusion:
interval() creates an infinite stream of numbers,
starting from 0 and continuing every N milliseconds.
Very handy when you need to do something regularly over time.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.