Skip to main content

WebAssembly

Updated 2 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/webassembly

In short

WebAssembly is a compact binary code format that runs in web browsers at near-native speed, letting languages like C++, Rust, and Go power fast web code.

What is WebAssembly?

WebAssembly, usually shortened to Wasm, is a low-level instruction format that browsers can run alongside JavaScript. Developers rarely write it by hand; instead they compile code written in languages such as C, C++, Rust, Go, or C# into a .wasm file, which the browser downloads, validates, and turns into fast machine code.

Wasm is designed for work that is too heavy for JavaScript alone, such as image and video editing, 3D games, design and CAD tools, audio processing, scientific computing, and running AI models in the browser. It also lets teams reuse existing libraries written in other languages on the web instead of rewriting them in JavaScript.

A Wasm module runs in a sandbox with no direct access to the page, the network, or files; it can only use what JavaScript explicitly passes to it. JavaScript loads the module, calls its exported functions, and handles the DOM, so the two work as partners. Think of JavaScript as the manager who talks to customers and WebAssembly as the specialist in the back room who does the heavy calculations.

A common misconception is that WebAssembly is meant to replace JavaScript. It is a complement: most web UI code is still written in JavaScript or TypeScript, and Wasm handles the performance-critical parts. WebAssembly also runs outside browsers, on servers, edge platforms, and plugin systems, where the WebAssembly System Interface (WASI) gives it controlled access to files and other system resources.

Key takeaways

  • WebAssembly (Wasm) is a binary format that runs at near-native speed.
  • Code in languages like C++, Rust, and Go can be compiled to Wasm.
  • It runs in a secure sandbox and works alongside JavaScript.
  • It suits heavy tasks like games, media editing, and in-browser AI.
  • WASI lets Wasm run outside the browser, on servers and at the edge.

Example

Loading a WebAssembly module from JavaScriptjavascript
// Load a compiled module (for example, one written in Rust or C++)
const { instance } = await WebAssembly.instantiateStreaming(
  fetch("/math.wasm")
);

// Call a function exported by the module like a normal JS function
const result = instance.exports.add(2, 3);
console.log(result); // 5

Readers ask

Will WebAssembly replace JavaScript?

No. WebAssembly is designed to work alongside JavaScript, not replace it. JavaScript still handles most UI work and access to the DOM, while Wasm speeds up computation-heavy parts.

Is WebAssembly faster than JavaScript?

For CPU-heavy work such as number crunching, image processing, or physics, WebAssembly is usually faster and more predictable. For typical UI code, modern JavaScript engines are already fast, and passing data back and forth between the two has its own cost.

Can WebAssembly access the DOM?

Not directly. A Wasm module can only call functions that JavaScript provides to it, so DOM updates go through JavaScript, often via glue code generated by the compiler toolchain.

See also

Spotted a mistake or something missing on this page?Suggest an edit

Read a random page
Open today's review
Switch to the dark theme
Read this page in Türkçe

More

Settings