Bird
0
0

Consider this pseudocode for a REST API endpoint:

medium📝 Predict Output Q13 of 15
Rest API - Rate Limiting and Throttling
Consider this pseudocode for a REST API endpoint:
function getUserData() {
  try {
    return fetchUserFromDB();
  } catch (error) {
    return { name: "Guest", id: 0 };
  }
}

What will getUserData() return if the database fetch fails?
AAn error message
BNothing, the function crashes
CNull
DA default user object with name 'Guest' and id 0
Step-by-Step Solution
Solution:
  1. Step 1: Analyze try block behavior

    If fetchUserFromDB() works, it returns user data.
  2. Step 2: Analyze catch block fallback

    If an error occurs, catch returns default user object with name 'Guest' and id 0.
  3. Final Answer:

    A default user object with name 'Guest' and id 0 -> Option D
  4. Quick Check:

    Error fallback returns default user object [OK]
Quick Trick: Catch returns default object on failure [OK]
Common Mistakes:
  • Assuming function crashes on error
  • Expecting null instead of fallback object
  • Thinking error message is returned

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes