What is RxJS, and what is the difference between switchMap, mergeMap, concatMap and exhaustMap?
RxJS models values arriving over time as Observables. Angular uses them throughout — HttpClient, router events, and form value changes all return them.
The four flattening operators all take a value, produce an inner observable, and flatten the result. They differ in what happens when a new value arrives while an inner observable is still running:
switchMap— cancel the previous inner observable and switch to the new one. Use for a type-ahead search: you only want results for the latest keystroke, and it cancels the in-flight request.mergeMap— run them all concurrently, results arriving in whatever order they finish. Use for independent parallel work where order does not matter.concatMap— queue them and run one at a time in order. Use when order matters, such as a sequence of writes that must be applied in sequence.exhaustMap— ignore new values while one is still running. Use for a submit button: it makes double-clicks harmless.
Note: Using switchMap for a save request is a classic bug — a second click cancels the first save, which may have already reached the server.





