Home › Learn › JavaScript

JavaScript

40 lessons, 8 modules, JavaScript running in your browser.

Start the course

JavaScript is the language browsers run, so the browser is the natural place to learn it. Each lesson explains one idea, gives you a task and an editor, and runs your code in an isolated sandbox the moment you press Run. The checks say what they expected and what your code produced; hints and a reference solution are a click away.

The course covers the language itself, the part that is the same whether you later build web pages, servers with Node, or scripts: values, decisions, loops, arrays and objects, strings, functions in depth, and finally promises, async/await, errors, and classes. It ends in a project, a checkout that turns an order into a receipt, that is not started from nothing: lessons along the way build its parts, saved in this browser as you go, and the project loads them before your code. Forty lessons, each about ten minutes.

What you will learn

The final project

The course ends with Project: checkout: a checkout that turns an order into a receipt, assembled from your own functions. 11 of the lessons build a part of it, saved in this browser as you go, so the project is assembled from your own work rather than started from nothing.

  1. TAX_RATE (let and const) is the sales tax rate the receipt applies.
  2. shippingCost (Functions) decides the shipping line of the receipt: free from 50 dollars, 5.99 below.
  3. pad (while loops) lines up the receipt columns by padding each label to a fixed width.
  4. sum (reduce, find, some, every) adds up a list of numbers; the receipt total is a sum.
  5. cartTotal (Arrays of objects) adds up price times quantity over the items in an order.
  6. money (Parsing and formatting numbers) formats every amount on the receipt as US dollars.
  7. addDays (Dates) works out the delivery date from the order date.
  8. makeDiscount (Closures) builds the function that applies an order's coupon rate.
  9. fetchStock (Promises) looks up how many of a product are in stock, asynchronously, like a server call.
  10. validateOrder (Errors: throw, try, catch) refuses an order with no items or a bad quantity before any money is worked out.
  11. Receipt (Classes) collects the labeled amounts of an order and totals them.

Lessons

Getting started

  1. Hello, worldPrint with console.log and see how lessons are checked.
  2. let and constStore values under names, and choose whether they can change.part: TAX_RATE
  3. Numbers and mathArithmetic, remainders, powers, and the Math object.
  4. Strings and template literalsJoin text and put values inside it with backticks.
  5. Reading error messagesLearn what ReferenceError, TypeError, and SyntaxError mean by fixing them.

Making decisions

  1. Comparisons and logicAsk questions about values and combine the answers.
  2. if and elseRun a block only when a condition holds.
  3. else if and switchChoose one of several outcomes.
  4. The ternary operator and truthinessOne-line decisions, and which values count as false.
  5. FunctionsPackage code under a name with inputs and a result.part: shippingCost

Loops

  1. for loopsRepeat a block a counted number of times.
  2. while loopsRepeat until a condition stops holding.part: pad
  3. break and continueLeave a loop early, or skip one round.
  4. Nested loopsA loop inside a loop covers every combination.
  5. FizzBuzzThe classic loop-and-conditions exercise.

Arrays

  1. ArraysOrdered lists you can grow, shrink, and index.
  2. Iterating arraysfor...of, forEach, and entries.
  3. map and filterTransform every item, or keep some of them.
  4. reduce, find, some, everyBoil an array down to one value, or ask questions about it.part: sum
  5. Sorting and slicingOrder arrays correctly and take parts of them.

Objects

  1. ObjectsGroup named values together.
  2. Arrays of objectsThe shape most real data takes.part: cartTotal
  3. Destructuring and spreadPull values out of objects and arrays, and copy or merge them.
  4. JSONTurn data into text and back, the way APIs and files do.
  5. Map and SetKeyed collections and unique collections.

Strings and numbers

  1. String methodsSplit, join, trim, replace, and search text.
  2. Characters and reversingWalk a string one character at a time.
  3. Parsing and formatting numbersText to number, number to text, safely.part: money
  4. DatesCreate dates, read their parts, and measure between them.part: addDays
  5. Regular expressionsFind and replace patterns in text.

Functions in depth

  1. Arrow functionsThe short function syntax, and when it differs.
  2. Default and rest parametersOptional parameters and any number of arguments.
  3. Functions as valuesPass functions in, get functions out.
  4. ClosuresFunctions remember the variables around them.part: makeDiscount
  5. RecursionA function that calls itself on a smaller problem.

Async, errors, and classes

  1. PromisesValues that arrive later, and what to do when they do.part: fetchStock
  2. async and awaitWrite asynchronous code that reads top to bottom.
  3. Errors: throw, try, catchRefuse bad input loudly and recover from failures.part: validateOrder
  4. ClassesBundle data with the methods that work on it.part: Receipt
  5. Project: checkoutAssemble the parts you built along the way into a checkout that turns an order into a receipt.final project