0Pricing
JavaScript Academy · Lesson

The Event Object

Read event details like target and type.

The Event Object is a free JavaScript Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Event Argument

When an event fires, the browser passes an event object to your handler. It carries details about what happened and which elements are involved.

btn.addEventListener("click", (event) => {
  console.log(event.type); // "click"
});

event.type

event.type is the name of the event, letting one handler react differently to different event types.

function handle(e) {
  console.log("Got a " + e.type + " event");
}

event.target

event.target is the element where the event actually originated, the deepest element that was interacted with.

list.addEventListener("click", (e) => {
  console.log(e.target); // the exact clicked element
});

event.currentTarget

event.currentTarget is the element whose listener is currently running, the one you called addEventListener on.

list.addEventListener("click", (e) => {
  console.log(e.currentTarget === list); // true
});

target vs currentTarget

When events bubble, target can be a child while currentTarget is the parent listening. This distinction powers event delegation.

list.addEventListener("click", (e) => {
  // e.target = clicked <li>
  // e.currentTarget = the <ul>
});

Event Delegation

Attach one listener to a parent and use target.closest to find which child was acted on. This scales better than many listeners.

list.addEventListener("click", (e) => {
  const item = e.target.closest("li");
  if (item) console.log(item.dataset.id);
});

event.timeStamp

event.timeStamp records when the event was created, useful for measuring durations between events.

btn.addEventListener("click", (e) => {
  console.log(e.timeStamp);
});

Coordinates on Mouse Events

Mouse events add positional data like clientX/clientY (relative to the viewport) and pageX/pageY (relative to the document).

area.addEventListener("click", (e) => {
  console.log(e.clientX, e.clientY);
});

Modifier Keys

Properties like e.shiftKey, e.ctrlKey, e.altKey, and e.metaKey tell you which modifier keys were held.

btn.addEventListener("click", (e) => {
  if (e.shiftKey) console.log("Shift-click");
});

event.isTrusted

event.isTrusted is true for real user-generated events and false for events created by script, helping distinguish genuine input.

btn.addEventListener("click", (e) => {
  console.log(e.isTrusted);
});

Reading the Key

Keyboard events expose e.key (the character or name) so you can react to specific keys.

input.addEventListener("keydown", (e) => {
  if (e.key === "Enter") console.log("submit");
});

Quick Check

Distinguish the two targets.

Recap

The event object describes the event: type, target (where it originated), and currentTarget (where the listener is). Their difference enables event delegation. Events also expose coordinates, modifier keys, key, timeStamp, and isTrusted.

Frequently asked questions

Is the “The Event Object” lesson free?

Yes — the full text of “The Event Object” is free to read here on the web, and the JavaScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the JavaScript Academy course, upgrade to CoddyKit PRO.

What will I learn in “The Event Object”?

Read event details like target and type. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start JavaScript Academy?

No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “The Event Object” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this JavaScript Academy lesson?

Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. addEventListener Basics
  2. The Event Object
  3. preventDefault and stopPropagation
  4. Keyboard and Mouse Events
← Back to JavaScript Academy