Bird
0
0

Given this NestJS controller method:

medium📝 component behavior Q13 of 15
NestJS - Pipes
Given this NestJS controller method:
@Get(':active')
getStatus(@Param('active', ParseBoolPipe) active: boolean) {
  return active ? 'Active' : 'Inactive';
}
What will be the response if the client requests /true?
A"Active"
B"Inactive"
C400 Bad Request error
D"true"
Step-by-Step Solution
Solution:
  1. Step 1: Understand ParseBoolPipe behavior

    ParseBoolPipe converts string 'true' to boolean true.
  2. Step 2: Evaluate the method return based on boolean value

    Since active is true, the method returns 'Active'.
  3. Final Answer:

    "Active" -> Option A
  4. Quick Check:

    Input 'true' -> boolean true -> returns 'Active' [OK]
Quick Trick: ParseBoolPipe converts 'true' string to boolean true [OK]
Common Mistakes:
  • Expecting string 'true' instead of boolean
  • Assuming 400 error for valid boolean string
  • Confusing output with input string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes