# Variable and Constant Declarations

## Constant Declaration

Whenever declaring a new constant, you must specify the type of the constant and then use `=` operator to assign values:

```
Num foo = 123
```

```javascript
const foo = 123;
```

Constants forbidden reassignment:

```
Num foo = 123
foo = 456
```

The sample code above throws error:

```
ParserError: Constant `foo` cannot be reassigned
```

## Variable Declaration

Wyrd introduce a keyword `mutable` in order to declare variables:

```
mutable Num foo = 123
```

It will compiled into JavaScript with `let` variable declaration:

```javascript
let foo = 123;
```

Hence, reassignment is now permitted:

```
mutable Num foo = 123
foo = 456
```

```javascript
let foo = 123;
foo = 456;
```

And of course, if you already declared a constant, redeclared as mutable variable throws error:

```
Num foo = 123
mutable Num foo = 456
```

```
ParserError: Constant `foo` cannot be redeclared as variable
```

## "maybe" Types Declaration

There are cases where you might need a variable to assign value represents the concept of **empty**. In Wyrd, everything about empty is represented as a primitive type of value `Null`.&#x20;

On the other hand, Wyrd introduced `maybe` types which can store either `Null` value or declared type. However, since the declared variable should have mutability, not only the keyword `maybe` involves, but also `mutable` keyword as well:

```
mutable maybe Num foo = 123
foo = Null
foo = 456
```

```javascript
let foo = 123;
foo = null;
foo = 456;
```

Since mutable variables can also be assigned `Null`, instead of directly assigned with `Null`, we can just omit the assignment and skip to next line, it will automatically assign the `maybe` type with `Null` value.

```
mutable maybe Num foo
```

```javascript
let foo = null;
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://maxwell-alexius.gitbook.io/wyrd/wyrd-syntax-rules/variable-and-constant-declarations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
