# Variables

<https://create.roblox.com/docs/luau/variables>\
\
In this section, we will discuss variables. A variable is a name that can hold data types such as booleans, numbers, strings, etc.&#x20;

### NAMING VARIABLES

When naming variables you **CANNOT** use space, number, and reserved names.

```lua
local myVariable = 'string' -- valid
local my_Variable = 1 -- valid
local my1stVariable = true -- valid

local 123 = 'string' -- not valid
local my variable = 1 -- not valid
local if = true -- not valid
```

### RESERVED NAMES LIST

| RESERVED NAMES |
| -------------- |
| and            |
| for            |
| or             |
| break          |
| function       |
| repeat         |
| do             |
| if             |
| return         |
| else           |
| in             |
| then           |
| elseif         |
| local          |
| true           |
| end            |
| nil            |
| until          |
| false          |
| not            |
| while          |

### GLOBAL & LOCAL VARIABLE

A variable can be <mark style="color:blue;">**GLOBAL**</mark> and <mark style="color:red;">**LOCAL**</mark>. <mark style="color:blue;">**GLOBAL**</mark> means it can be accessed everywhere in the script and <mark style="color:red;">**LOCAL**</mark> means it can be only accessed in a certain block of codes.

#### GLOBAL:

<pre class="language-lua"><code class="lang-lua">if 1 > 0 then --- if 1 is greater than 0 then the code will execute below.
  myVariable = 'Hello, World!!'
<strong>  print(myVariable) -- Hello, World!!
</strong>end

print(myVariable) -- Hello, World!!
</code></pre>

#### LOCAL:

<pre class="language-lua"><code class="lang-lua">if 1 > 0 then --- if 1 is greater than 0 then the code will execute below.
  local myVariable = 'Hello, World!!'
<strong>  print(myVariable) -- Hello, World!!
</strong>end

print(myVariable) -- nil
</code></pre>
