惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
Y
Y Combinator Blog
I
InfoQ
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - Franky
IT之家
IT之家
H
Help Net Security
月光博客
月光博客
S
SegmentFault 最新的问题
B
Blog
aimingoo的专栏
aimingoo的专栏
GbyAI
GbyAI
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
U
Unit 42
Vercel News
Vercel News
博客园 - 叶小钗
Microsoft Security Blog
Microsoft Security Blog
腾讯CDC
Jina AI
Jina AI
T
The Blog of Author Tim Ferriss

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
`setTimeout()` Is NOT Part of JavaScript
CodeWithIshw · 2026-05-09 · via DEV Community

CodeWithIshwar

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 handles timers and async I/O

The OS performs the actual waiting.

Once the timer completes:

1. The callback enters the task queue
2. The event loop detects it
3. JavaScript executes it when the call stack is empty

---

# Simplified internal implementation

Browser/runtime internals conceptually look like this:



```cpp id="8b45pi"
void SetTimeoutCallback(args) {
  StartTimer(delay, [=]() {
    task_queue.push(jsCallback);
  });
}

Enter fullscreen mode Exit fullscreen mode

The important takeaway:

➡️ The timer itself never runs inside JavaScript.


Why JavaScript feels asynchronous

JavaScript is single-threaded.

So how can it handle:

  • timers
  • networking
  • file systems
  • user events

without blocking?

Because the expensive work happens outside the JS engine entirely.

JavaScript delegates async operations to native runtime systems.

The event loop simply coordinates completed work back into JS execution.


This architecture powers almost everything

API Backed by
fetch() Native networking stack
addEventListener() Browser event system
console.log() Native stdout handling
fs.readFile() OS file system calls
Timers Browser APIs / libuv

Why understanding this matters

Once you understand this model, concepts like:

  • Event Loop
  • Async/Await
  • Promises
  • Node.js internals
  • Browser APIs
  • Performance bottlenecks

become much easier to reason about.

One of the biggest mindset shifts in JavaScript is realizing:

JavaScript itself is actually a very small language.

Most of the “magic” developers use daily comes from the runtime around it.