Menu

1 / 2

`setTimeout()` Is Not Actually JavaScript

Open Forem·CodeWithIshwar·6 months ago
#UTtIYq7C
Reading 0:00
15s threshold

One of the biggest misconceptions I had early in my career was believing JavaScript itself handled things like:

timers

network requests

DOM events

file system operations

It turns out…

JavaScript engines like V8 don’t actually implement any of those features.

Take this example:

```js id="g7q2vn"

setTimeout(() => {

console.log("Hello");

}, 2000);

Most developers assume:

> JavaScript starts a timer and waits 2 seconds.

But that’s not what happens.

---

# What V8 Actually Does

V8 only handles:

* parsing JavaScript * compiling JavaScript * executing JavaScript

That’s it.

It has no built-in understanding of:

* timers * HTTP requests * mouse clicks * file systems * sockets

Those capabilities are provided by the runtime environment around V8.

Depending on where your code runs, that runtime could be:

* the browser * Node.js * Deno * Bun

---

# So who handles `setTimeout()`?

When you call:

```js id="dx9s1f" setTimeout(fn, 2000);

Enter fullscreen mode

Exit fullscreen mode

the flow looks…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.