Question 2Easy
What does the pipe symbol do in {{ price | currency }}?
- Passes the value through a pipe to format it for display
- Performs a logical OR
- Declares a template variable named after the pipe
- Calls a service method with the value
Answer: A. Passes the value through a pipe to format it for display
Explanation
Pipes transform values in templates.
Step-by-step solution
- Pipe -> transform.
Why the other options are wrong
- B. The pipe symbol is not a logical OR; it formats the value.
- C. Pipes are not template variables; they transform the displayed value.
- D. Pipes transform values; they do not call service methods.
Question 3Medium
What does the async pipe do?
- Makes a method asynchronous
- Sorts items asynchronously on a worker thread
- Subscribes to an observable or promise and unsubscribes automatically
- Caches HTTP responses in memory
Answer: C. Subscribes to an observable or promise and unsubscribes automatically
Explanation
It renders the latest value and triggers change detection.
Step-by-step solution
- Subscribe in template.
Why the other options are wrong
- A. The async pipe does not make a method asynchronous.
- B. The async pipe does not sort items or use worker threads.
- D. The async pipe does not cache responses; it only subscribes.
Question 5Medium
By default, a custom pipe is pure. When does a pure pipe re-run?
- When its input value or arguments change by reference/primitive value
- On every change detection pass
- Only once at application startup
- Every second on a timer
Answer: A. When its input value or arguments change by reference/primitive value
Explanation
Pure pipes are skipped if inputs are unchanged.
Step-by-step solution
- Pure = memoised.
Why the other options are wrong
- B. A pure pipe skips checks unless its inputs change.
- C. A pure pipe re-runs on input change, not only at start-up.
- D. A pure pipe has no timer; it re-runs on input changes.
Tip: Use pure: false sparingly.
Question 6Hard
A pure pipe filters an array, and code calls arr.push(x) on the same array. What happens?
- The pipe re-runs automatically on each mutation of the array contents
- The pipe does not re-run because the array reference is unchanged
- Angular throws an error about mutation
- The array is cloned before the push
Answer: B. The pipe does not re-run because the array reference is unchanged
Explanation
Pure pipes compare references, so mutate-in-place goes unnoticed.
Step-by-step solution
- Same reference.
Why the other options are wrong
- A. A pure pipe ignores in-place mutation of the same array reference.
- C. Angular throws no error on array mutation; the pipe just stays stale.
- D. Angular never clones the array before a push; it mutates it.
Tip: Create a new array instead.