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
- Use closures to hold private state
- Model things with classes and inheritance
- Handle failures so that programs recover
- Predict the order of asynchronous code
- Split a program into modules with clear interfaces
Lessons
- 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
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
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
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
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
- A function that makes functionsEasy
- Named counters with closuresMedium
- Remember the answersHard
- A Rectangle classEasy
- A bank account classMedium
- A family of shapesHard
- Dividing safelyEasy
- Read JSON safelyMedium
- Validating recordsHard
- One job at a timeEasy
- Which timer fires first?Medium
- Try again when it failsHard
- A private scoreEasy
- A shopping cart moduleMedium
- A tiny module loaderHard