Example 1 — Log on click (MDN)
Show whether the Shift key is pressed on each click.
const log = document.querySelector("#log");
document.addEventListener("click", function (e) {
log.textContent = "The shift key is pressed: " + e.shiftKey;
}); How It Works
- Listen for
click. MDN’s basic demo event. - Read
e.shiftKey. Boolean for Shift at that moment. - Update the log. Instant feedback for students.
- Hold Shift and click again. The value flips to
true.

