Test your understanding of RxJS basics with this 15-question quiz covering Observables, subscriptions, Streams, and core RxJS operators. Perfect for beginners preparing for interviews or wanting to boost their knowledge of reactive programming in JavaScript and Angular.
1. RxJS Purpose
What is the primary purpose of RxJS in JavaScript development?
- To handle asynchronous data streams using Observables
- To process CSS styles
- To compile TypeScript into JavaScript
- To create server-side applications only
2. Observable Concept
Which statement best describes an Observable in RxJS?
- A method to generate HTML markup
- A static variable used in JavaScript
- A data stream that can emit multiple values over time
- A function that returns a single value synchronously
3. Observer Callback Example
If an Observer subscribes to an Observable, which of the following methods can it implement to receive emitted values?
- push()
- add()
- finish()
- next()
4. Subscription Role
What is the role of a Subscription in RxJS?
- It generates events on button clicks
- It stores static data
- It represents the execution and allows cancellation of an Observable
- It defines HTTP endpoints
5. Creation Functions
Which RxJS function can you use to easily create an Observable that emits values 1, 2, and 3?
- each()
- on()
- of()
- emit()
6. Subjects and BehaviorSubject
What is a key difference between a Subject and a BehaviorSubject in RxJS?
- Subjects cannot be subscribed to
- Subjects require an initial value, but BehaviorSubjects do not
- BehaviorSubjects require an initial value and always emit the latest value to new subscribers
- Both are exactly the same
7. Operator Differences
When should you use switchMap instead of mergeMap in RxJS?
- When you want to ignore all incoming Observables
- When you want to cancel the previous Observable if a new one is emitted
- When you want to process Observables sequentially
- When you want to run all inner Observables in parallel
8. Pipe Functionality
What does the pipe() function do in RxJS?
- It filters out errors but nothing else
- It imports RxJS libraries
- It chains multiple operators together to transform data streams
- It closes the Observable
9. takeUntil Use Case
Why would a developer use the takeUntil() operator in RxJS?
- To delay emissions for a set time
- To increase emission speed
- To complete an Observable when another emits a value
- To convert hot Observables to cold
10. Error Handling
Which operator would you use within RxJS to handle errors in an Observable stream?
- handleError()
- catchError()
- emitError()
- tryCatch()
11. Hot vs Cold Observables
Which scenario describes a cold Observable in RxJS?
- Requires an initial static value
- Never emits any values
- Always emits values whether subscribed or not
- Emits values only when there are active subscribers, like an HTTP request
12. debounceTime Operator
How does debounceTime() behave when used with keyboard input in a search field?
- It ignores all input values
- It emits a value only if a specified time has passed since the last input
- It emits a value immediately after each keystroke
- It amplifies each keystroke to multiple values
13. Memory Leak Prevention
Which RxJS pattern helps prevent memory leaks in Angular components?
- Never unsubscribing from Observables
- Using takeUntil() to automatically unsubscribe
- Storing Subscriptions globally
- Making all Observables infinite
14. forkJoin Usage
What does forkJoin() return when used with multiple Observables?
- Emissions as soon as any Observable emits
- The last emitted value from each Observable after all complete
- Values in the order Observables were created
- A stream with only the first emitted value
15. Testing Observables
Which method is commonly used for testing RxJS Observables and their emissions over time?
- Sequence checking
- Stateful validation
- End-to-end timing
- Marble testing