WebAssembly
WebAssembly (Wasm) is a compact code format that browsers can run alongside JavaScript. It lets web apps use code compiled from languages such as Rust and C++ without rewriting it in JavaScript.
Also known as: Wasm
What WebAssembly is
WebAssembly is a standardized instruction format, not a programming language you need to learn to write a web app. A compiler can take a library written in C, C++, or Rust and produce a .wasm module. That module is not tied to a particular processor: the browser checks it and translates its instructions for the device it runs on. For example, a photo editor can reuse an existing image codec instead of reimplementing it in JavaScript.
The boundary between JavaScript and Wasm
A module describes code and data; an instance is what you get when you instantiate that module and supply any required imports. Imports let the module use capabilities supplied by its host, such as a JavaScript function that logs a message. Exports are the functions or other values the module exposes to its caller. In a browser, Wasm has no built-in way to query the DOM or send an HTTP request. The host has to provide those capabilities, typically through JavaScript.
A module can store bytes in linear memory, which is a contiguous address space indexed by byte offsets. If the module exports that memory, JavaScript can access its buffer through a typed array. To send audio samples to a routine, for instance, JavaScript can place the bytes in linear memory and pass an offset and a length. A JavaScript array of objects is not automatically converted into that layout; the integration layer needs to handle the conversion.
A minimal browser example
Suppose math.wasm exports add, needs no imports, and is served with the MIME type application/wasm. The streaming API can start compiling while the file is still downloading:
const { instance } = await WebAssembly.instantiateStreaming(
fetch('/math.wasm')
);
console.log(instance.exports.add(2, 3)); // 5
Real libraries often ship with generated JavaScript bindings that handle loading, memory allocation, and data conversion.
When it helps and when it doesn't
Wasm is useful for porting existing libraries and running compute-heavy tasks such as decompression, audio processing, or game simulation. It is not a blanket speed upgrade over JavaScript. A fast routine can still make the app slower if every call must copy a large buffer or if the app crosses the JS–Wasm boundary once per pixel. Also, asynchronous loading does not make calls to Wasm exports run in the background. A long call on the main thread can freeze the UI; a Web Worker can keep that work off the main thread.
How it comes up in interviews
If asked whether to move an image filter to Wasm, start by identifying the bottleneck. A slow pixel loop is a plausible candidate; a delay caused by downloading the image is not. Compare processing a whole buffer in one call with an equivalent JavaScript implementation. Measure the complete operation, including data preparation and, on the first run, downloading and initializing the module.