Bird
0
0

Why does this FileValidationPipe code fail to reject files larger than 1MB?

medium📝 Debug Q7 of 15
NestJS - Pipes
Why does this FileValidationPipe code fail to reject files larger than 1MB?
transform(file) {
  if (file.size > 1_000_000) {
    throw new BadRequestException('File too large');
  }
  return file;
}
AThe file size is checked in bytes, but the file size is in kilobytes
BThe condition should use '>=' instead of '>'
CThe underscore notation is not supported in JavaScript numbers
DThe pipe must be async to work correctly
Step-by-Step Solution
Solution:
  1. Step 1: Understand numeric literals in JavaScript

    Underscore separators in numbers are supported only in ES2021+; older environments fail.
  2. Step 2: Identify if underscore usage causes syntax error

    If environment does not support it, the code will throw a syntax error and fail.
  3. Final Answer:

    The underscore notation is not supported in JavaScript numbers -> Option C
  4. Quick Check:

    Underscores in numbers need ES2021+ support [OK]
Quick Trick: Use underscores in numbers only if environment supports ES2021+ [OK]
Common Mistakes:
  • Assuming underscores always work in numbers
  • Confusing bytes with kilobytes
  • Thinking async is needed for validation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes