How JavaScript really works

The ideas that separate someone who can write JavaScript from someone who understands it: closures, objects and prototypes, error handling, the event loop and modules.

About 13 hours of study

Learning objectives

Lessons

  1. 1

    Scope and closures

    Where a variable can be seen: global, function and block scope, shadowing, hoisting and the temporal dead zone, and closures: functions that remember the variables around them.

  2. 2

    Classes and prototypes Intermediate

    Making many objects of one shape with class: constructors, methods, getters, static members, private fields, inheritance with extends and super, and the prototype chain underneath.

  3. 3

    Errors: throw, try and catch

    The kinds of errors JavaScript throws, reading an error message, throw, try, catch and finally, your own error classes, and checking input before using it.

  4. 4

    Asynchronous JavaScript: event loop, promises, async/await Intermediate

    Why JavaScript never waits: callbacks and setTimeout, the event loop with its task and microtask queues, promises with then and catch, async functions and await, and fetching data.

  5. 5

    Modules: splitting a program into files Intermediate

    Why large programs are split into files, how import and export work, the module pattern that came before them, and how a program's parts can depend on each other safely.

Module practice

Module quiz

1. What is printed? let x = 1; function f() { console.log(x); } x = 2; f();
2. A loop with var creates three functions that print i. What do they all print?
3. Where do methods defined in a class body live?
4. Why is throwing an error often better than returning a special value such as -1?
5. What is the order of output? setTimeout(()=>log("a")); Promise.resolve().then(()=>log("b")); log("c");
6. Two independent requests take 2 and 3 seconds. About how long does Promise.all take?
7. What is the main benefit of giving a module a small public interface?

‹ Functions and dataJavaScript in the browser ›