Bird
0
0

In a microservice using a watcher to reload config on changes, what is the expected output?

medium📝 Analysis Q5 of 15
Microservices - Configuration and Secrets Management
In a microservice using a watcher to reload config on changes, what is the expected output?
config = {"timeout": 30}
function watchConfig() {
  onChange(newConfig) {
    config = newConfig
  }
}
watchConfig()
// Config update
onChange({"timeout": 45})
print(config["timeout"])
A30
Bnull
Cerror
D45
Step-by-Step Solution
Solution:
  1. Step 1: Check function scope of onChange

    onChange is defined inside watchConfig but called outside, causing scope error.
  2. Step 2: Understand why error occurs

    onChange is not accessible globally, so calling it outside causes an error.
  3. Final Answer:

    error -> Option C
  4. Quick Check:

    Scope error due to onChange usage [OK]
Quick Trick: Callback must be accessible where called to avoid errors [OK]
Common Mistakes:
  • Assuming config updates without scope errors
  • Expecting old value printed
  • Ignoring function scope rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes