Skip to content

What is WebAssembly?

WebAssembly (WASM) is a compact binary instruction format designed as a portable compilation target for programming languages. It enables high-performance applications to run on the web.

Core Features

FeatureDescription
Binary formatEfficient binary-encoded code
Stack machinePush/pop based architecture
Type safetyStrong type system, only four value types
Memory modelDynamically growable linear memory
SandboxedIsolated execution environment

How It Works

WASM's simple example:

wat
;; WAT (WebAssembly Text Format) — human-readable representation
(module
  (func $add (param i32 i32) (result i32)
    local.get 0
    local.get 1
    i32.add)
  (export "add" (func $add)))

From JavaScript:

javascript
// Exported functions can be called directly
const result = instance.exports.add(40, 2);
console.log(result); // 42

WebAssembly vs JavaScript

AspectJavaScriptWebAssembly
FormatTextBinary
Parse speedSlowerFaster
ExecutionJIT compiledDirect execution
Type systemDynamicStatic
GC supportBuilt-inLimited
DOM accessDirectVia JS interop

When to Use WASM

Use WebAssembly in these scenarios:

  • Performance-critical code — Image/video processing, game engines, codecs
  • Port existing codebases — Reuse C/C++/Rust libraries in Web
  • Compute-intensive tasks — Scientific computing, encryption, compression
  • Near-native performance — Signal processing, physics simulation

TIP

WebAssembly doesn't replace JavaScript — it's a complement to JavaScript. Use WASM for compute-intensive tasks while keeping JavaScript for DOM manipulation and business logic.

Browser Support

All modern browsers support WebAssembly:

BrowserSupported From
Chrome57+
Firefox52+
Safari11+
Edge16+

What's Next

Now that you know what WebAssembly is, let's set up the development environment.

Released under the MIT License.