3 mins read

Introduction

Motoko is a programming language used for developing canisters on the Internet Computer Protocol (ICP). One of the best things about Motoko is its strong type system. This system helps us catch errors early, before our code runs, which means fewer bugs and more reliable applications.

Just like languages like Rust, TypeScript, and Swift, Motoko makes it easier to write safe, clean code and avoid common mistakes. This makes it a great choice for building secure, scalable apps that run on the Internet Computer.

Primitive Types in Motoko

Primitive types are the basic building blocks of data in Motoko. These types are built into the language itself and are used to store simple values. They include:

These primitive types form the foundation of data handling in Motoko. They help ensure that your data is used correctly and efficiently.

Example usage


actor Example {
  let isReady: Bool = true;
  let count: Nat = 10;
  let temperature: Int = -5;
  let pi: Float = 3.14;
  let greeting: Text = "Hello, Motoko!";
}

Non-Primitive Types in Motoko

Sometimes we need to work with more complex data than what primitive types can offer. That’s where non-primitive types come in. These include things like arrays, records, and tuples.

Example usage