1. Home
  2. /
  3. Assemblyscript
  4. /
  5. Simple AssemblyScript Function

Simple AssemblyScript Function - Assemblyscript Typing CST Test

Loading…

Simple AssemblyScript Function — Assemblyscript Code

A basic AssemblyScript function that adds two numbers and returns the result.

# assemblyscript/demo/add.ts
export function add(a: i32, b: i32): i32 {
	return a + b;
}

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

Subtract Two NumbersMultiply Two NumbersDivide Two NumbersFactorial FunctionFibonacci FunctionCheck Even NumberCheck Odd NumberMaximum of Two NumbersMinimum of Two Numbers

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher