> For the complete documentation index, see [llms.txt](https://zaidlang.gitbook.io/z/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zaidlang.gitbook.io/z/language/variables.md).

# Variables

Variables are named slots for storing values. You define a new variable in Zaidlang using the `=` operator, like so:

```dart
a = 1 + 2
```

This creates a new variable `a` in the current scope and initializes it with the result of the expression following `=`. Once a variable has been defined, it can be accessed by name as you would expect.

```dart
technology = "Micromachines"

printftw(technology) // >> Micromachines
```

### Scope <a href="#scope" id="scope"></a>

Zaidlang has true block scope: a variable exists from the point where it is defined until the end of the block where that definition appears.

```dart
function foobar() {
  printftw(a) // Error: "a" doesn't exist yet.

  a = 123

  printftw(a) // >> 123
}

printftw(a) // Error: "a" doesn't exist anymore.
```

Variables defined at the top level of a script are *top-level*, or *global*. All other variables are *local*. Declaring a variable in an inner scope with the same name as an outer one is called *shadowing* and is not an error.

```dart
a = "outer"

function foobar() {
  a = "inner"

  printftw(a) // inner
}

printftw(a) // outer
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://zaidlang.gitbook.io/z/language/variables.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.
