RxJS вопросы и ответы для интервью
Вопрос 16. How does error handling work in RxJS Observables?
Errors in Observables can be handled using the 'catchError' operator, which allows you to catch and handle errors within the Observable stream.
Example:
const errorHandledObservable = observable.pipe(catchError(err => of('Error handled:', err)));
Вопрос 17. What is the purpose of the 'distinctUntilChanged' operator in RxJS?
'distinctUntilChanged' filters out consecutive duplicate values emitted by an Observable, only allowing distinct values to be emitted.
Example:
const distinctObservable = observable.pipe(distinctUntilChanged());
Вопрос 18. Explain the concept of 'Schedulers' in RxJS.
Schedulers are used to control the execution context and timing of Observable operations, allowing you to control when and where certain code is executed.
Example:
const scheduledObservable = observable.pipe(delay(1000, asyncScheduler));
Вопрос 19. What is the purpose of the 'zip' operator in RxJS?
'zip' is used to combine multiple Observables by emitting values in a strict sequence, combining corresponding values from each Observable.
Example:
const zippedObservable = zip(observable1, observable2, (value1, value2) => value1 + value2);
Вопрос 20. Explain the use of the 'interval' function in RxJS.
'interval' creates an Observable that emits sequential numbers at a specified interval, creating a timer-like behavior.
Example:
const intervalObservable = interval(1000);
Самое полезное по оценкам пользователей: