Bird
0
0

What will be the output of this code snippet?

medium📝 Analysis Q5 of 15
LLD - Behavioral Design Patterns — Part 2
What will be the output of this code snippet?
class Mediator {
  notify(sender, event) {
    if (event === 'start') {
      console.log(sender + ' started');
    } else {
      console.log('Unknown event');
    }
  }
}
const mediator = new Mediator();
mediator.notify('ComponentX', 'stop');
AUnknown event
BError: event not handled
CComponentX started
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Check event condition in notify

    Only 'start' event logs sender started; others log 'Unknown event'.
  2. Step 2: Analyze call with event 'stop'

    Since event is 'stop', else branch executes printing 'Unknown event'.
  3. Final Answer:

    Unknown event -> Option A
  4. Quick Check:

    Event 'stop' triggers unknown event log [OK]
Quick Trick: Only 'start' event logs sender started, others print unknown [OK]
Common Mistakes:
MISTAKES
  • Assuming 'stop' triggers 'started' message
  • Expecting error instead of else output
  • Thinking no output for unknown events

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes