# Variables

Giving a name to a value makes it easier to refer back to it later. When you assign a name, you can change its value later and all references to that value change automatically. These names are called "variables", and you create them using `=`.

``````lunch = \$12
dinner = \$24
lunch + dinner``````
``````\$12
\$24
\$36``````

In Figures, a variable can use multiple words and even emoji 🤩.

``````shrimp pasta 🍤 = \$17
spaghetti and meatballs = \$11
tax rate = 8%
shrimp pasta 🍤 + tax rate``````
``````\$17
\$11
8%
\$18.36``````

## Changing a Variable's Value

Once you change the value of a variable, all future calculations will use the new value.

``````appetizers = \$9
main dish = \$21
dessert = \$6
appetizers + main dish + dessert

dessert = \$10
appetizers + main dish + dessert``````
``````\$9
\$21
\$6
\$36

\$10
\$40``````

Variables must be assigned a value before they're used. If no value has been given, Figures will automatically ignore the name until it has a value.

``````my variable
my variable = 42
my variable``````
``````
42
42``````

## Line Variables

Figures can also create a variable that has no name using a "line variable". Drag a result from a previous line to create a line variable. Just like regular variables, the line variable's value updates automatically whenever the answer for that line changes.

NOTE

A line variable can only reference one of the previous lines

If you prefer typing, you can also just type in the line you want to reference. Use the word `line` followed by the line number (no space between them). When you move the cursor or keep typing, the text will be converted to a line variable for you.

``````pi × 2
line1``````
``````6.28
6.28``````

If you'd like to lock in the value of a line variable so it won't change anymore, you can double-click it to convert it to regular text. If you prefer the keyboard, you can also select the line variable and press `Return`.

## Explicit Variable Declaration

Variables are normally assigned using the simple method described above, but there are situations that require a more advanced method. Consider a case where you want to assign a new value for the constant `pi`. Since `pi` is defined by the system as a constant value, it can't be changed. Instead, use the word `var` before the assignment to create a new variable. The original value is still available by prefacing the name with the system sheet called `Figures`.

``````pi = 3
var pi = 3
pi × 2
Figures.pi × 2``````
``````●
3
6
6.28``````

NOTE

See Imports for more on referencing variables from other sheets

You can create your own constant variables that cannot be changed by using the word `let` before the assignment. This can be useful when you want to be sure a variable isn't accidentally changed. A new variable is created just like with `var`, but an error will be displayed if it's assigned a new value.

``````let constant = 42
constant += 5``````
``````42
●``````

## Case Sensitivity

Most names are not case sensitive. This means that typing `abs(-1)` and `Abs(-1)` gives the same result. There are some situations where the case can be important, though. For example, unit and prefix symbols can mean different things based on the case:

``````32 b  // bits
32 B  // bytes

12m  // meters
12M  // mega prefix

23y  // yocto prefix
23Y  // yotta prefix``````
``````32 b
32 B

12 m
12 million

2.3 × 10⁻²³
23 septillion``````

If you need to define a variable as case sensitive, add `^` to the end of the name when you define it. Figures will then only recognize the variable if the name matches exactly.

``````Dinner^ = \$15
dinner
Dinner``````
``````\$15

\$15``````

Didn't find what you were looking for?