A binary instruction format for a stack-based virtual machine that enables high-performance execution in web browsers.
Back to TutorialsWebAssembly is a binary instruction format that enables execution of code compiled from multiple programming languages (like Rust, C/C++) in web browsers with near-native performance. It complements JavaScript by executing complex tasks at higher speeds.
WASM uses a low-level binary format that browsers can interpret efficiently. The compilation workflow typically involves:
// Rust code (lib.rs)
#[no_mangle]
pub extern fn add(a: i32, b: i32) -> i32 {
a + b
}
// Compile with:
// rustc --target wasm32-unknown-unknown --crate-type=cdylib lib.rs
JavaScript Integration:
// Load and run the WebAssembly module
fetch('add.wasm')
.then(response => response.arrayBuffer())
.then(bytes => WebAssembly.instantiate(bytes, {}))
.then(results => {
const addFunction = results.instance.exports.add;
console.log(addFunction(10, 20)); // Output: 30
});
Ideal for computationally intensive work like image processing, 3D rendering, audio manipulation, and complex simulations.
Reuse legacy codebases or domain-specific algorithms written in C/C++/Rust without rewriting in JavaScript.
Try converting a performance-critical algorithm to Rust and compiling it with WebAssembly. Use our interactive code editor to experiment.
Next Step: Advanced WebAssembly Patterns