Intermediate JavaScript
Intermediate JavaScript is where the language starts to feel like a system. You have already learned values, functions, arrays, objects, the DOM, and events. Now you will learn what happens when code fails, waits, remembers hidden state, uses `this`, imports other files, and talks to outside services. This part has more moving pieces than the earlier parts. Do not rush it. Some ideas, especially closures, `this`, promises, and the event loop, often take more than one reading. That is not a problem. These topics are difficult because they describe behavior you cannot always see directly. You will learn how to read errors instead of fearing them, how scope controls where values live, how closures preserve state, how prototypes and classes share behavior, how asynchronous code works, and how APIs send data to your programs. By the end of this part, you should be able to read common real-world JavaScript without feeling like the language changed underneath you. You will know how to work with code that fails, waits, imports, exports, and fetches data.
Chapters
Error Handling
Every programmer meets errors. That is not a warning. It is just how programming works. You write code, JavaScript reads it, something does not line up, and JavaScript tells you. Sometimes the message is clear. Sometimes it is noisy. Sometimes the code runs without crashing and still gives the wrong answer. This chapter is about learning how to respond. You do not need to memorize every possible error message. You need a reliable process: read the message, find where JavaScript noticed the problem, inspect the values involved, and decide whether the program should recover or whether the code needs to be fixed. This chapter builds that process: reading common errors, following stack traces, debugging with logs and breakpoints, handling expected failures with `try...catch`, throwing your own errors when input is bad, and not hiding real bugs by accident.
Scope and Closures
Variables do not live everywhere. When you create a variable, JavaScript stores it in a place. Some places are wide open. Some places are small. Some variables can be used across much of a file. Some can be used only inside one function or one pair of braces. Scope is the rule that decides where a variable can be used. Closures are what happen when a function remembers variables from the place where it was created, even after that place has finished running. That sounds strange the first time you hear it. A function can remember? In JavaScript, yes. Not in a magical way. A function carries a link to the surrounding variables it needs. That link is what makes counters, event handlers, private state, and many real-world JavaScript patterns work. This chapter works through global scope, function scope, block scope, and the scope chain, then turns to closures: how they hold on to state, why each one can keep its own private data, and how to use them without tangling up your code.
this, Prototypes, and Classes
JavaScript has more than one way to create objects that share behavior. You already know object literals: ```js const user = { name: "Ada", greet() { return `Hello, ${this.name}`; } }; ``` This chapter explains the pieces behind that small example. The first piece is `this`, a special value that often points to the object a method was called on. The second piece is the prototype system, which lets objects inherit properties and methods from other objects. The third piece is class syntax, which gives you a cleaner way to create many objects with the same behavior. These topics have a reputation for being confusing. Some of that reputation is earned. `this` does not work like a normal variable, and classes in JavaScript are not a separate object system. They are built on prototypes. You do not need to master every strange edge case right away. You need the practical rules: how `this` is chosen, how methods are shared, when to use classes, and how to avoid the mistakes that show up in beginner code. So this chapter sticks to the practical rules: writing methods that use `this`, borrowing methods with `call`, `apply`, and `bind`, building objects from prototypes, and writing classes with constructors, methods, getters, setters, static methods, private fields, and inheritance.
Asynchronous JavaScript
Some code finishes right away. Some code starts now and finishes later. That difference changes how you write JavaScript. When JavaScript adds two numbers, the answer is available immediately. When it waits for a timer, asks a server for data, reads a file, or waits for a user click, the result comes later. The program cannot freeze while it waits. A browser page would stop responding. A server would stop helping other users. Asynchronous JavaScript is how JavaScript starts slow work, keeps running, and comes back to the result when it is ready. This chapter shows how the pieces fit together: callbacks, promises, `async` and `await`, timers, and the event loop. It also covers handling errors in async code and steering clear of the mistake almost every beginner makes, which is trying to use a value before it exists.
Working with APIs
An API is a way for programs to talk to each other. On the web, an API often means a URL that returns data instead of a finished page. Your JavaScript sends a request. The server sends back a response. Your code reads that response and updates the page. This chapter connects the async tools from Chapter 19 to real web data. You will learn what APIs are, how JSON works, how `fetch` sends requests, why `response.ok` matters, how query parameters are built, and how to build a small weather app with loading and error states.
Modern JavaScript Features (ES6+)
Modern JavaScript gives you tools for organizing files, reading nested values safely, storing specialized collections, and creating custom iteration. These features are not decorations. Each one solves a problem developers kept running into. Modules help split code across files. Optional chaining avoids crashes when a nested value is missing. Nullish coalescing gives fallbacks without treating `0` and `""` as missing. `Map` and `Set` handle data shapes that plain objects and arrays do not always handle cleanly. Generators and symbols show up less often in beginner projects, but they explain some advanced JavaScript behavior you will see in documentation and libraries.