1. Home
  2. /
  3. Assemblyscript
  4. /
  5. Fibonacci Function

Fibonacci Function - Assemblyscript Typing CST Test

Loading…

Fibonacci Function — Assemblyscript Code

Calculates Fibonacci number recursively.

# assemblyscript/demo/fibonacci.ts
export function fibonacci(n: i32): i32 {
	if(n <= 1) return n;
	return fibonacci(n - 1) + fibonacci(n - 2);
}

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.

More Assemblyscript Typing Exercises

Simple AssemblyScript FunctionSubtract Two NumbersMultiply Two NumbersDivide Two NumbersFactorial FunctionCheck Even NumberCheck Odd NumberMaximum of Two NumbersMinimum of Two Numbers

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher