Language Foundations · 10 min read · Beginner
Variables, Events & the DOM
Select HTML elements, react to clicks with addEventListener, and log state to the live console.
What you'll learn
- Declare variables cleanly with const and let
- Query elements using document.querySelector
- Respond to user clicks with addEventListener and update textContent
JavaScript turns static HTML and CSS into interactive experiences. The browser exposes your HTML page as the DOM (Document Object Model), a tree of objects your script can read and update.
const vs. let
- Use
constby default for values you will not reassign (including DOM references likeconst button = ...). - Use
letwhen a value changes over time (like a counter or score).
Try It Yourself
Click +1 or Reset in the preview, and watch both the UI and the Console Output update live!
Interactive Counter + Console
Live Result
Console Output
No console output yet. Try calling console.log(...) in JS.
Check Your Understanding
Score: 0 / 1
1. Which property is safest for setting plain text inside a DOM element?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.