WebAssembly: Get Started in 10 Minutes

Learn how to compile, run, and interact with your first WebAssembly module

Start Tutorial

What is WebAssembly?

WebAssembly (wasm) is a low-level binary instruction format that's fast, portable across platforms, and integrates well with existing web technologies.

This tutorial will show you how to:

Step-by-Step: Creating Your First WebAssembly Example

Step 1: Write the C Source Code


extern int add_two(int a);

int add_two(int a) {
 return a+2;
}

Step 2: Compile to WebAssembly

emcc -O3 -s WASM=1 -s EXPORTED_FUNCTIONS="['_add_two']" -o add2.wasm add_two.c

Step 3: Load and Execute in Web


fetch('add2.wasm')
 .then(response => response.arrayBuffer())
 .then(bytes => WebAssembly.instantiate(bytes))
 .then(results => {
 const { add_two } = results.instance.exports;
 console.log(add_two(5)); // Output: 7
 });

What Can You Do Next?