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
constdeclares a variable that can't be reassigned after it's set, use it by default.letdeclares a variable you can reassign later, use it when a value needs to change (like a counter).varis the old way of declaring variables, from beforelet/constexisted, 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!