Add a click listener to a button
The Trade DeskSoftware Engineer · Technical ScreenLast updated
Add a click listener to a button evaluates requirements, assumptions, structured reasoning, trade-offs, and verification in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.
Given an HTML page that includes a button with the id 'my-button', write JavaScript to add a click event listener so that when the button is clicked, the button's text content is logged to the console. Use document.querySelector and addEventListener. Briefly explain what e.target refers to in this context.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.