Modern JavaScript Essentials

Lesson 1 of 6

JavaScript in the Browser

JavaScript is the one programming language that runs natively in every web browser, it's what makes pages interactive: reacting to clicks, fetching data, and updating content without a full page reload.

Your first JavaScript

JavaScript

Declaring variables

  • const declares a variable that can't be reassigned after it's set, use it by default.
  • let declares a variable you can reassign later, use it when a value needs to change (like a counter).
  • var is the old way of declaring variables, from before let/const existed, you'll still see it in older code, but modern JavaScript avoids it.
JavaScript

The DOM

In a real page, JavaScript reads and modifies the DOM (Document Object Model), the live tree of elements your code can change:

const button = document.querySelector('#greet');
button.addEventListener('click', () => {
  document.querySelector('#out').textContent = 'Hello!';
});

DOM code needs a real web page, so that block is read-only here, every other example in this course is runnable. Try the first one!

📝 DOM Quiz

Passing score: 70%
  1. 1.What does DOM stand for?

  2. 2.To react to a click you call element.____("click", handler).