Variables & Types

Harbor uses bare assignment for variables and has two value types: strings and numbers.

Variable assignment

Variables are created by assigning a value to a name. There is no let, var, const, or set keyword. Just write the name, an equals sign, and the value.

x = 10
name = "Harbor"
port = 8080

Variables can be reassigned at any time:

x = 10
x = 20
print(x)  // not yet supported, but conceptually: prints 20

Note: There are no type annotations. The type of a variable is determined by the value assigned to it.

Strings

String literals use double quotes. Single quotes are not supported.

greeting = "Hello, world!"
path = "/api/users"

Strings can be concatenated with the + operator:

base = "Hello, "
who = "Harbor"
message = base + who

There are no escape sequences (like \n or \t) and no string interpolation.

Numbers

Number literals are integers in the source code, but are stored internally as 64-bit floating point values.

port = 8080
count = 42

Numbers can be added with the + operator:

a = 10
b = 20
sum = a + b

Other types

Harbor does not have booleans, arrays, null, or user-defined objects. The req object inside route handlers is an internal object type — see Request Object.

Scope

Variables declared at the top level are global. Variables declared inside a function are local to that function. Function parameters are also local.