import ballerina/io;

// Modules and functions can declare variables. You can see both in this example.
// Here we declare a variable `greeting` of type `string` and initialize it to `"Hello"`.
string greeting = "Hello";

public function main() {
    // Assignments are statements not expressions.
    string name = "Ballerina";

    io:println(greeting, " ", name);
}

Variables and Types

A variable has a type, which constrains what values the variable can hold. There is a built-in set of named types, including int, float, boolean, string.

import ballerina/io;
string greeting = "Hello";

Modules and functions can declare variables. You can see both in this example. Here we declare a variable greeting of type string and initialize it to "Hello".

public function main() {
    string name = "Ballerina";

Assignments are statements not expressions.

    io:println(greeting, " ", name);
}
bal run variables_and_types.bal
Hello Ballerina