Bird
0
0

A developer wrote this code snippet to check a feature toggle but it always activates the feature regardless of toggle state:

medium📝 Analysis Q14 of 15
Microservices - Configuration and Secrets Management
A developer wrote this code snippet to check a feature toggle but it always activates the feature regardless of toggle state:
if (featureToggle.isEnabled = true) {
  enableFeature();
} else {
  disableFeature();
}
What is the main error causing this behavior?
AFeature toggle name is incorrect
BUsing assignment '=' instead of comparison '==' in the if condition
CMissing parentheses around the condition
DCalling the wrong method name for toggle check
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the if condition syntax

    The condition uses assignment '=' which sets isEnabled to true, always true.
  2. Step 2: Identify correct comparison operator

    It should use '==' or a method call to compare, not assignment.
  3. Final Answer:

    Using assignment '=' instead of comparison '==' in the if condition -> Option B
  4. Quick Check:

    Assignment in if condition causes always true [OK]
Quick Trick: Check if condition uses '==' not '=' [OK]
Common Mistakes:
  • Confusing assignment '=' with equality '=='
  • Assuming method name is wrong without checking syntax
  • Ignoring parentheses importance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes