Menu

1 / 2

`setTimeout()` Is NOT Part of JavaScript

DEV Community·CodeWithIshwar·6 months ago
#6xf7n9BN
#why#javascript#webdev#programming#runtime
Reading 0:00
15s threshold

Most developers write this code every day:

```js id="e9u2xa"

setTimeout(() => {

console.log("Hello");

}, 2000);

and assume JavaScript is responsible for the timer.

But that’s not actually true.

## The surprising reality

JavaScript engines like V8 do **not** have built-in timer functionality.

V8 only knows how to:

* parse JavaScript * compile JavaScript * execute JavaScript

That’s it.

Functions like:

* `setTimeout()` * `fetch()` * `addEventListener()` * `console.log()`

are **not provided by JavaScript itself**.

They come from the runtime environment:

* Browsers * Node.js * Native system libraries

---

# What happens when `setTimeout()` runs?

When you execute:

```js id="n5lf4v" setTimeout(callback, 2000);

Enter fullscreen mode

Exit fullscreen mode

the flow is roughly:

```text id="38dxux"

JavaScript

↓

V8 Engine

↓

Runtime Bindings

↓

Native C/C++ APIs

↓

Operating System

The runtime delegates the timer to native code.

In browsers:

* Web APIs handle timers

In Node.js:

* libuv…

Continue reading — create a free account

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