A. res.status(400) is called after res.send, so status code is ignored
B. res.send cannot be called without res.status first
C. res.status must be called with a string, not a number
D. No error, this code works correctly
Solution
Step 1: Understand response flow in Express
Once res.send() is called, the response is sent and closed. Any code after it won't affect the response.
Step 2: Analyze order of calls
Here, res.send('Oops!') sends the response with default status 200. Then res.status(400) is called but ignored because response is already sent.
Final Answer:
res.status(400) is called after res.send, so status code is ignored -> Option A
Quick Check:
Call res.status before res.send to set status [OK]
Hint: Always call res.status before res.send or res.json [OK]
Common Mistakes:
Calling res.status after res.send expecting status change
Thinking res.send requires res.status first
Using string instead of number in res.status
5. You want to send a 204 No Content status with no response body in Express. Which code snippet correctly does this?
hard
A. res.status(204).send()
B. All of the above
C. res.status(204).json(null)
D. res.sendStatus(204)
Solution
Step 1: Understand 204 No Content meaning
Status 204 means the server successfully processed the request but returns no content in the response body (Content-Length: 0).
Step 2: Check each option's behavior
res.status(204).send() sends status 204 with empty body [check]. res.status(204).json(null) sends status 204 with JSON "null" body ✗. res.sendStatus(204) sends status 204 with "No Content" text body ✗. Only A sends no response body.
Final Answer:
res.status(204).send() -> Option A
Quick Check:
res.status(204).send() = 204 + empty body [OK]
Hint: Use res.status(204).send() for 204 with no body [OK]
Common Mistakes:
Sending body content with 204 status (should be empty)
Using res.status(204).json({}) which sends empty object body
Not sending response after setting status
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.