Skip to the content.

Data Types

Flexa is a statically-typed language, which means that every variable and expression has a type that is known at ‘compile’ time. Flexa supports a variety of data types, including primitive types, composite types, and special types. In this section, we’ll explore these types in detail.


Primitive Types

Primitive types are the basic building blocks of Flexa programs. They include:

1. Boolean (bool)

2. Integer (int)

3. Floating-Point (float)

4. Character (char)

5. String (string)


Composite Types

Composite types are used to group multiple values together. They include:

1. Arrays

2. Structs


Special Types

Flexa also supports special types for specific use cases:

1. Function (function)

2. Void (void)

3. Any (any)


Type Inference

Flexa supports type inference, which means you don’t always need to explicitly specify the type of a variable. The compiler can infer the type based on the assigned value. An inferred variable will always have the any type, wich means that will accepts values of any type.

var x = 10;       // x is any, but it's value is inferred as int
var y = 3.14;     // y is any, but it's value is inferred as float
var z = "Flexa";  // z is any, but it's value is inferred as string

Type Casting

Flexa allows you to explicitly convert values from one type to another using type casting.

var a: int = 10;
var b: float = float(a); // Cast int to float

What’s Next?

Now that you understand the data types supported by Flexa, it’s time to learn how to declare and use variables and constants. Head over to the Variables and Constants section to dive deeper.


← Back to Basic Syntax Next: Variables and Constants →