Skip to main content

WebAssembly with JavaScript

  • WebAssembly support for JavaScript is good thanks to Javy.
  • Javy compiles QuickJS, a tiny JavaScript runtime, to Wasm along with the script to be executed.
  • JavaScript is the second most popular and desirable language to work with WebAssembly.
  • TypeScript, a superset of JavaScript, can be transpiled into JavaScript before being compiled to Wasm.

Install Javy

Install Javy following the instructions here:


All of the build dependencies of the Javy toolchain have to be installed after cloning the GitHub repository.

JavaScript code

We will create a simple JavaScript application that will return us the Fibonacci sequence. Create a file named index.js:

function fibonacci(){
var num = 10;
var a = 1, b = 0, temp;

while (num >= 0){
temp = a;
a = a + b;
b = temp;
console.log("Fibonacci result is: ",b);


var Shopify = {
main: fibonacci

Access the JavaScript codex repository for code samples, including the fibonacci example.


The Javy toolchain expects Shopify.main to point to our main function, in this case, fibonacci.

Compile to Wasm

Navigate to /javy/target/release directory to generate the Wasm file using the ./javy executable. You will have to save your JavaScript source code in this directory as well.

./javy index.js -o index.wasm

Run with Enarx

Enarx run index.wasm