Bird
0
0

Given the following controller method, what will be the value of limit if the request URL is /items (no query parameters)?

medium📝 component behavior Q13 of 15
NestJS - Pipes
Given the following controller method, what will be the value of limit if the request URL is /items (no query parameters)?
@Get('items')
getItems(@Query('limit', new DefaultValuePipe(5)) limit: number) {
  return limit;
}
Aundefined
Bnull
C5
D0
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the request URL and query parameters

    The URL /items has no limit query parameter provided.
  2. Step 2: Understand DefaultValuePipe behavior

    Since limit is missing, DefaultValuePipe sets it to the default value 5.
  3. Final Answer:

    5 -> Option C
  4. Quick Check:

    Missing param uses default value 5 [OK]
Quick Trick: Missing query uses DefaultValuePipe value [OK]
Common Mistakes:
  • Assuming undefined when param is missing
  • Confusing null with default value
  • Expecting zero instead of default

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes