Lesson 1 of 9 · 20m
What WebAssembly Actually Is
The execution model behind Wasm — a sandboxed, typed, ahead-of-time-compiled guest inside the JavaScript host, not a magical faster JavaScript.
The first mistake people make with WebAssembly is treating it like 'JavaScript but faster.' It isn't. Wasm is a small, typed, low-level bytecode format executed in a sandboxed VM, with JavaScript acting as the host environment. The host owns the DOM, network, timers, and most platform APIs. The Wasm module owns linear memory and deterministic numeric computation.
The division of labor
A useful mental model is a foreign worker process embedded inside your page:
JavaScript host
- owns DOM, events, fetch, WebGL, workers
- loads and instantiates the module
- can read/write wasm memory if given access
WebAssembly module
- exports functions with fixed numeric signatures
- has one contiguous ArrayBuffer-backed linear memory
- cannot touch the DOM or network unless JS passes capabilities inThat boundary is the architecture. You don't sprinkle Wasm randomly through UI code; you move a self-contained computational kernel across the boundary and keep orchestration in JavaScript.
Why it can be fast
JavaScript is dynamically typed and shaped around objects that can mutate at runtime. Wasm is statically typed i32/i64/f32/f64 code with predictable memory layout. Engines can compile it ahead of time with fewer guards. Tight numeric loops, codecs, compression, parsing, simulation, and cryptography benefit most.
But the speed is not automatic. If your workload is mostly string manipulation, object churn, or DOM access, you are paying a boundary tax to run the wrong part of the program elsewhere.
Sandboxed does not mean harmless
Wasm has no ambient authority — it can only use imports the host gives it — but it still executes attacker-influenced code. A memory corruption bug in C or unsafe Rust can corrupt the module's own linear memory, and the host will happily parse the damaged results. Compile hardened source, treat outputs as untrusted, and don't confuse isolation with correctness.
Field notes
- Wasm modules are usually small VMs, not npm packages with superpowers.
- If your kernel can't be described as bytes in, bytes out, it probably isn't a good first Wasm candidate.
- JavaScript remains the control plane. Wasm is the compute plane.
- The most expensive mistake is crossing the boundary too often, not writing the wrong loop inside it.
Was this lesson helpful?