← Salesforce Interview Insights

Salesforce·Software Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Salesforce full-stack screen, one coding question the whole time. They wanted vanilla JS only which I wasn't expecting, and the discussion afterward about timer internals was honestly more involved than the implementation itself.

Questions Asked (1)

Q1

Using only HTML, CSS, and vanilla JavaScript (no frameworks), build a traffic light that cycles through red (4s), yellow (1s), and green (1s) indefinitely, with only one light active at a time. Also discuss timer management, pause/resume behavior, and cleanup.

Technical Trade-offsSystem Design
Author's notes

The DOM part was fine, took maybe ten minutes.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and edge cases, then outline a clean state-machine approach using setTimeout for precise timing and a single source of truth for the active light. Implement pause/resume by tracking remaining time and cleanup by clearing timers and removing event listeners.

Pro tip: Use a state machine with explicit states and transitions, and encapsulate timer logic in a class or module to avoid global variables and make pause/resume and cleanup straightforward.

1. Clarify Requirements and Constraints

Confirm the exact durations, whether the cycle starts on red, and if pause/resume should preserve remaining time. Ask about accessibility and visual design expectations.

2. Design the State Machine

Define states (red, yellow, green) and transitions with associated durations. Use a single variable to track the current state and a function to transition to the next state.

3. Implement Timer Management

Use setTimeout for each state's duration, storing the timer ID. For pause, clear the timeout and record the remaining time; for resume, set a new timeout with the remaining time.

4. Handle Pause/Resume and Cleanup

Implement pause/resume by tracking elapsed time and remaining time. Provide a cleanup method that clears any active timers and removes event listeners to prevent memory leaks.

5. Test and Discuss Trade-offs

Test edge cases like rapid pause/resume and cleanup during transitions. Discuss trade-offs between setTimeout and setInterval, and between using CSS classes vs inline styles.

Key Points to Mention

  • Use setTimeout instead of setInterval to avoid drift and overlapping timers.
  • Maintain a single source of truth for the active light and use CSS classes for styling.
  • For pause/resume, calculate remaining time using Date.now() and store it.
  • Cleanup should clear all timers and remove any event listeners to prevent memory leaks.
  • Consider accessibility: use ARIA roles and ensure the traffic light is understandable to screen readers.
  • Encapsulate logic in a class or module to avoid polluting the global scope and to make testing easier.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.