WASM
01 / 02

What WebAssembly Is & How It Fits with JavaScript

What WebAssembly Is & How It Fits with JavaScript

A Binary Compilation Target, Not a New Language

WebAssembly (WASM) is a low-level, portable binary instruction format designed to run at near-native speed in browsers and beyond. It's a compilation target, not something developers usually hand-write — toolchains like Emscripten (C/C++), wasm-pack (Rust), and TinyGo (Go) compile existing source into it.

Why It's Faster Than JavaScript for Compute

JavaScript engines parse text source and JIT-compile hot paths over time. WASM's compact binary format is designed for fast validation and near-instant compilation to efficient machine code — avoiding much of that parsing/warm-up overhead for compute-heavy work.

Complement, Not Replacement

WASM is not meant to replace JavaScript. The typical architecture: a WASM module exposes pure computation functions; JavaScript still handles DOM manipulation, browser API calls, and orchestration, calling into WASM for the CPU-heavy parts.

Loading a Module

const { instance } = await WebAssembly.instantiateStreaming(
  fetch('module.wasm')
)

const result = instance.exports.add(2, 3)

instantiateStreaming fetches, compiles, and instantiates a module in one streamed step — the recommended way to load .wasm files efficiently.

Sandboxing

WASM runs inside the same security sandbox as JavaScript — no direct filesystem, network, or arbitrary browser API access. Any such interaction must go through imported JavaScript functions explicitly provided when the module is instantiated.

Keep your own version of these notes — editable, searchable, and organised by your stack.

Start free