Bird
0
0

Consider this code snippet:

medium📝 component behavior Q5 of 15
Node.js - HTTP Module
Consider this code snippet:
res.setHeader('Content-Type', 'application/json');
res.setHeader('Content-Type', 'text/html');
res.end();

What will be the final Content-Type header sent to the client?
Aapplication/json
Bapplication/json, text/html
CNo Content-Type header
Dtext/html
Step-by-Step Solution
Solution:
  1. Step 1: Understand header overwriting behavior

    Setting the same header twice overwrites the previous value in Node.js.
  2. Step 2: Identify last set value

    The last setHeader call sets 'Content-Type' to 'text/html', which replaces 'application/json'.
  3. Final Answer:

    text/html -> Option D
  4. Quick Check:

    Last header set wins = C [OK]
Quick Trick: Last setHeader call for same header overwrites previous [OK]
Common Mistakes:
  • Assuming headers concatenate automatically
  • Expecting both values to be sent
  • Thinking first setHeader call persists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes