Common Async Operations in JavaScript
You'll learn: which everyday JavaScript operations are asynchronous and why recognizing them matters.
The Usual Suspects
Now that you understand what asynchronous code is, it's time to identify where you'll actually encounter it. JavaScript has several built-in operations that don't complete immediately—they need to wait for something external to happen.
Four Common Async Sources
1. setTimeout and setInterval
These timing functions schedule code to run later. Even setTimeout(fn, 0) is asynchronous—it doesn't block the main thread.
2. fetch (Network Requests)
When your code talks to a server, it waits for a response. The network is slow compared to your CPU, so fetch operations are always async.
3. File I/O (in Node.js)
Reading or writing files involves the operating system and disk drives. These operations take time and don't block JavaScript while they work.
4. Event Handlers
User interactions (clicks, key presses) and other events (page load, timers completing) happen at unpredictable times. Your event listeners run asynchronously when these events occur.
Why This Matters
Recognizing these operations helps you understand when your code will run. If you see setTimeout, you know that callback won't execute immediately. If you call fetch, you know you're waiting for network data. This awareness is the first step to writing correct asynchronous code.
Think of it like knowing which roads have stoplights: you don't need to memorize every traffic signal in your city, but recognizing "this is a major intersection" helps you plan your route.
Key Takeaway: setTimeout, fetch, file I/O, and event handlers are the most common async operations—whenever you use them, you're dealing with code that won't complete right away.