Pipes Questions with Answers

6 practice questions on Pipes (Angular) with answers and step-by-step solutions. Try 6 samples below, then practise all 6 free in the AptiNest app.

Sample questions

Question 1Easy

Which built-in pipe formats a Date value?

  1. datetime
  2. date
  3. time
  4. format

Answer: B. date

Explanation

{{ d | date:'shortDate' }}.

Step-by-step solution

  1. Name the pipe.

Why the other options are wrong

  • A. datetime is not a built-in Angular pipe; the name is date.
  • C. time is not a built-in Angular pipe for formatting dates.
  • D. format is not a built-in pipe; the date pipe formats dates.

Question 2Easy

What does the pipe symbol do in {{ price | currency }}?

  1. Passes the value through a pipe to format it for display
  2. Performs a logical OR
  3. Declares a template variable named after the pipe
  4. 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

  1. 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?

  1. Makes a method asynchronous
  2. Sorts items asynchronously on a worker thread
  3. Subscribes to an observable or promise and unsubscribes automatically
  4. 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

  1. 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 4Medium

What do you implement to build a custom pipe?

  1. OnInit with a pipe method
  2. Directive with a transform selector
  3. PipeTransform with a transform method
  4. Injectable with a format method

Answer: C. PipeTransform with a transform method

Explanation

Decorate with @Pipe({name}) and implement transform.

Step-by-step solution

  1. @Pipe + transform.

Why the other options are wrong

  • A. Custom pipes implement PipeTransform, not OnInit.
  • B. A directive with a transform selector is not how pipes are built.
  • D. An Injectable with a format method is not a pipe.

Question 5Medium

By default, a custom pipe is pure. When does a pure pipe re-run?

  1. When its input value or arguments change by reference/primitive value
  2. On every change detection pass
  3. Only once at application startup
  4. 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

  1. 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?

  1. The pipe re-runs automatically on each mutation of the array contents
  2. The pipe does not re-run because the array reference is unchanged
  3. Angular throws an error about mutation
  4. 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

  1. 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.

Practise all 6 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Angular topics · All topics