Learn Assemblyscript - 10 Code Examples & CST Typing Practice Test
AssemblyScript is a TypeScript-like language that compiles to WebAssembly (Wasm). It allows developers familiar with TypeScript/JavaScript to write high-performance WebAssembly modules for web, server, and blockchain applications.
Learn ASSEMBLYSCRIPT with Real Code Examples
Updated Nov 25, 2025
Code Sample Descriptions
Simple AssemblyScript Function
# assemblyscript/demo/add.ts
export function add(a: i32, b: i32): i32 {
return a + b;
}
A basic AssemblyScript function that adds two numbers and returns the result.
Subtract Two Numbers
# assemblyscript/demo/subtract.ts
export function subtract(a: i32, b: i32): i32 {
return a - b;
}
Subtracts one number from another.
Multiply Two Numbers
# assemblyscript/demo/multiply.ts
export function multiply(a: i32, b: i32): i32 {
return a * b;
}
Multiplies two integers and returns the result.
Divide Two Numbers
# assemblyscript/demo/divide.ts
export function divide(a: i32, b: i32): i32 {
return a / b;
}
Divides one number by another, integer division.
Factorial Function
# assemblyscript/demo/factorial.ts
export function factorial(n: i32): i32 {
if(n <= 1) return 1;
return n * factorial(n - 1);
}
Calculates factorial of a number recursively.
Fibonacci Function
# assemblyscript/demo/fibonacci.ts
export function fibonacci(n: i32): i32 {
if(n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
Calculates Fibonacci number recursively.
Check Even Number
# assemblyscript/demo/isEven.ts
export function isEven(n: i32): bool {
return (n % 2) == 0;
}
Returns true if a number is even.
Check Odd Number
# assemblyscript/demo/isOdd.ts
export function isOdd(n: i32): bool {
return (n % 2) != 0;
}
Returns true if a number is odd.
Maximum of Two Numbers
# assemblyscript/demo/max.ts
export function max(a: i32, b: i32): i32 {
return a > b ? a : b;
}
Returns the maximum of two integers.
Minimum of Two Numbers
# assemblyscript/demo/min.ts
export function min(a: i32, b: i32): i32 {
return a < b ? a : b;
}
Returns the minimum of two integers.
Frequently Asked Questions about Assemblyscript
What is Assemblyscript?
AssemblyScript is a TypeScript-like language that compiles to WebAssembly (Wasm). It allows developers familiar with TypeScript/JavaScript to write high-performance WebAssembly modules for web, server, and blockchain applications.
What are the primary use cases for Assemblyscript?
High-performance web modules. Blockchain smart contracts (e.g., NEAR Protocol, Polkadot parachains). Game engines or physics simulations in the browser. Data processing in the browser or edge environments. Embedding Wasm modules in Node.js or serverless platforms
What are the strengths of Assemblyscript?
Leverages TypeScript knowledge for Wasm development. Produces small, fast WebAssembly binaries. Supports both client-side and server-side execution. Works with existing JS code via imports/exports. Enables blockchain contracts on Wasm-based chains
What are the limitations of Assemblyscript?
Not full TypeScript - some features (generics, classes) are limited. Manual memory management may be required for advanced use. Limited standard library compared to JS or Rust. Debugging can be more complex than JS. Tooling and ecosystem smaller than Rust/C++ for Wasm
How can I practice Assemblyscript typing speed?
CodeSpeedTest offers 10+ real Assemblyscript code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.