JavaScript
JavaScript is the language that makes web pages interactive. It runs in every browser and, these days, on servers too.
Variables and types
Declare values with let and const. The core types are numbers, strings, booleans, arrays, objects, null and undefined.
const name = 'Ada';
let count = 0;
const list = [1, 2, 3];
const user = { name, age: 36 };
Functions
Functions group code you want to reuse. Arrow functions are a short way to write them.
function add(a, b) { return a + b; }
const double = (n) => n * 2;
The DOM
In the browser, JavaScript changes the page through the DOM, the live tree of elements. You find elements, read them, change them, and react to events.
document.querySelector('#go').addEventListener('click', () => {
document.body.style.background = '#eef';
});
Promises and async
Anything that takes time, loading data, waiting for a response, returns a promise. async/await lets you write it like ordinary step-by-step code.
async function load() {
const res = await fetch('/data.json');
return res.json();
}