Factorial Function - Assemblyscript Typing CST Test
Loading…
Factorial Function — Assemblyscript Code
Calculates factorial of a number recursively.
# assemblyscript/demo/factorial.ts
export function factorial(n: i32): i32 {
if(n <= 1) return 1;
return n * factorial(n - 1);
}Assemblyscript Language Guide
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.
Primary Use Cases
- ▸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
Notable Features
- ▸TypeScript-like syntax with optional static typing
- ▸Direct compilation to WebAssembly
- ▸Small and efficient Wasm output
- ▸Supports import/export with JavaScript
- ▸Active open-source ecosystem and tooling
Origin & Creator
AssemblyScript is an open-source project maintained by the AssemblyScript community, started around 2017.
Industrial Note
AssemblyScript is ideal for web developers seeking performance-critical modules, blockchain developers building smart contracts on Wasm chains, and projects that need a bridge between TypeScript and WebAssembly.