Bird
Raised Fist0

What will be printed when the following Mediator code is executed?

medium📝 Analysis Q4 of Q15
LLD - Behavioral Design Patterns — Part 2
What will be printed when the following Mediator code is executed?
class Mediator {
  notify(sender, event) {
    if (event === 'login') {
      console.log(sender + ' logged in');
    }
  }
}
const mediator = new Mediator();
mediator.notify('User1', 'login');
ANo output
Blogin
Cundefined logged in
DUser1 logged in
Step-by-Step Solution
Solution:
  1. Step 1: Check notify method logic

    It checks if event equals 'login' and then logs sender + ' logged in'.
  2. Step 2: Analyze input parameters

    sender is 'User1' and event is 'login', so condition is true.
  3. Final Answer:

    User1 logged in -> Option D
  4. Quick Check:

    Condition matches event, correct output printed [OK]
Quick Trick: Check event condition matches input event string [OK]
Common Mistakes:
MISTAKES
  • Confusing sender and event parameters
  • Assuming no output if event mismatches
  • Ignoring string concatenation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes