Bird
0
0

Which of the following is the correct way to use DefaultValuePipe to set a default value of 10 for a query parameter named page?

easy📝 Syntax Q12 of 15
NestJS - Pipes
Which of the following is the correct way to use DefaultValuePipe to set a default value of 10 for a query parameter named page?
A@Query('page', new DefaultValuePipe(10)) page: number
B@Query('page', DefaultValuePipe(10)) page: number
C@Query('page', DefaultValuePipe) page: number = 10
D@Query('page', new DefaultValuePipe) page: number = 10
Step-by-Step Solution
Solution:
  1. Step 1: Check the syntax for using pipes in NestJS

    Pipes are instantiated with the new keyword and passed as the second argument to decorators like @Query.
  2. Step 2: Confirm the correct usage of DefaultValuePipe

    The DefaultValuePipe requires a value in its constructor, so new DefaultValuePipe(10) is correct.
  3. Final Answer:

    @Query('page', new DefaultValuePipe(10)) page: number -> Option A
  4. Quick Check:

    Use new DefaultValuePipe(value) with decorator [OK]
Quick Trick: Always use 'new' to instantiate DefaultValuePipe [OK]
Common Mistakes:
  • Omitting 'new' keyword when creating the pipe
  • Passing DefaultValuePipe without parentheses
  • Assigning default value directly in parameter without pipe

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes