A. It does not check if age is a number before comparing.
B. It uses res.send instead of res.json.
C. It should use GET instead of POST method.
D. It does not handle missing age with a default value.
Solution
Step 1: Analyze input usage
The code compares age without verifying if it's a number, which can cause errors if age is missing or a string.
Step 2: Check other options
Using res.send is valid, POST is correct for submit, and missing default is less critical than type check.
Final Answer:
It does not check if age is a number before comparing. -> Option A
Quick Check:
Validate input type before use = It does not check if age is a number before comparing. [OK]
Hint: Always check input types before using them [OK]
Common Mistakes:
Thinking res.send is wrong here
Confusing HTTP methods for form submission
Ignoring type checks causes runtime errors
5. You want to ensure a user's email and password meet these rules: email must be a valid email format, password must be at least 8 characters. Which approach best applies input validation in Express?
hard
A. Check password length only, ignoring email format.
B. Trust the client-side validation only and save data directly.
C. Save data first, then validate asynchronously later.
D. Use express-validator to check email format and password length, then send errors if invalid.
Solution
Step 1: Identify proper validation method
express-validator allows checking both email format and password length on the server side before saving.
Step 2: Evaluate other options
Relying only on client-side or partial validation risks bad data; saving before validation is unsafe.
Final Answer:
Use express-validator to check email format and password length, then send errors if invalid. -> Option D
Quick Check:
Server-side validation with express-validator = Use express-validator to check email format and password length, then send errors if invalid. [OK]
Hint: Validate all inputs server-side before saving [OK]