Events — Complete Guide
Events — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of JavaScript Tutorial on Toolliyo Academy.
On this page
JavaScript Tutorial · Lesson 52 of 100
Events
Basics ✓ → Objects & data ✓ → Async & DOM → Advanced → Tools → Projects
Intermediate · 3 — Async & DOM · ~6 min · JS HTML DOM & Web APIs
What is this?
Events are things that happen — click, keypress, submit, load. You listen with addEventListener and run a function when the event fires.
Why should you care?
Every button, form, and keyboard shortcut in a web app is wired through events.
See it live — copy this example
Paste into an HTML file or the browser console (F12). Use Run below when the live editor is available.
<input id="name" placeholder="Type your name" />
<p id="out"></p>
<script>
const input = document.getElementById("name");
const out = document.getElementById("out");
input.addEventListener("input", () => {
out.textContent = "Hello, " + input.value;
});
</script>
Run Example »
Edit the code below and click Run to see the result in Toolliyo’s live editor.
What happened?
- The input event fires on every keystroke.
- input.value reads the text box.
- The paragraph updates live as you type.
Practice next
- Type in input and watch live hello message.
- Add form submit with e.preventDefault().
- Log event.type inside handler.
- Listen for keydown Enter on the input to trigger an action.
- Use event.target vs event.currentTarget on nested elements.
Remember
addEventListener("event", handler) Common: click, input, submit event.target is the element that fired
ScriptVerse live preview
Markdown editor fires input events to re-render preview on every keystroke.
Outcome: Event-driven UI keeps forms responsive and familiar to users.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!