JavaScript from the ground up
Make the page do something
- Beginner
- 12 chapters
- 179 min read
A hands-on first course in JavaScript, from your first console line to a small app built with the DOM and events: every idea comes with a page you can change and watch react in the same editor, with a short quiz at the end of each chapter.
What You'll Learn
- Run a script and read what the console says
- Store values, and build sentences from them
- Make decisions and repeat work with loops
- Write functions that take values and return answers
- Keep data in arrays and objects, and walk it
- Find elements on the page and change them
- React to clicks, typing and submissions
- Read a form, validate it, and answer in place
- Clone a template and open a native dialog
- Define an element of your own with a shadow root and slots
- Build a small app with nothing but the language
- Reach for the language’s own tools — iterator helpers, set methods, Object.groupBy
Prerequisites
- Some HTML — the HTML course on this site, or any page you can open in an editor
- No programming experience needed; the course starts at the first line
Vocabulary
The terms the chapters assume, in plain words.
- addEventListener
- A call on an element that registers a listener for one kind of event.
- closest
- A way to find the nearest parent of an element that matches a rule you give, starting with the element itself.
- closure
- A function together with the variables from the place it was written, which stay available when it runs later.
- default behaviour
- What the browser does on its own when an event happens, such as following a link or submitting a form, before any script intervenes.
- DOM
- The tree of objects a browser builds from the page, which a script can read and change while the page is open.
- element
- One item in the page tree, such as a heading or a button, which a script can find and change.
- event
- Something that happens on the page, such as a click, a key press, or a form being submitted, which a script can respond to.
- event bubbling
- The way an event rises from the element that received it up through each of its parents.
- event target
- The element that actually received the action, which may be a child of the element whose listener is running.
- function
- A reusable block of code that can be called with values and can return an answer to whoever called it.
- handler
- The function you give to a listener, which the browser runs when the event it waits for happens.
- listener
- A function registered on an element to wait for one kind of event and run each time that event reaches it.
- property
- A named value stored on an object, usually read and written with a dot, such as the text of an element.
- reference
- A value that points at an object rather than holding a copy, so a change made through one is visible through the other.
- scope
- The part of a program where a name can be used, decided by where it was declared.
- variable
- A name that holds a value so you can use it again; a constant cannot be pointed at a different value later.
Course Content
- 01How JavaScript worksNot started
The third language of the web: what a script is for, how the page loads one, and where its output appears.
- 02Values and variablesNot started
Names for values: const for the ones that stay, let for the ones that change, and building sentences with template literals.
- 03Decisions and loopsNot started
Asking questions with if, repeating work with for, and walking a list with the for…of shape.
- 04FunctionsNot started
A name for a piece of work: parameters in, a return value out, and arrow functions for the short ones.
- 05Arrays and objectsNot started
Many values under one name: lists in order, records with named fields, and the two or three methods worth knowing.
- 06The page as a treeNot started
Finding elements on a page and changing them: querySelector, textContent, and building new elements to append.
- 07EventsNot started
The page answering back: listening for clicks, reading what happened, and keeping state between events.
- 08Forms and validationNot started
Reading what a visitor typed, stopping the page from reloading, and answering with a message that helps.
- 09Templates and dialogsNot started
Markup you can stamp out and a modal the browser operates: clone a template, fill it, and open it as a dialog.
- 10An element of your ownNot started
Inventing a tag and teaching the browser what it renders: a class, a shadow root, slots, and one line to register it.
- 11A small app, end to endNot started
Everything at once: a to-do list that reads a field, listens for a submit, builds list items and keeps the page in step.
- 12The newest JavaScriptNot started
Three additions that remove a page of helper code each: iterator helpers that work a step at a time, set methods that do real set algebra, and the small conveniences around them.
