# Understand nested variables

> How a variable reference can sit inside another variable's path or stored value, and how Buttons resolves it from the inside out.

Nesting lets one variable reference help build the name or the value of another, instead of every reference needing to be a fixed, literal variable. This can help when the exact variable you need depends on something else that changes (such as picking a variable by index or by another variable's current value) rather than being known in advance. There are two distinct ways a variable reference can nest. Nesting inside a variable's path A variable reference can contain another variable reference inside its own path, resolved from the inside out. For example: $(something.ab_$(something.b)) Buttons resolves the inner reference, $(something.b) , first, then substitutes the result into the outer path before resolving that. This lets you build the name of the variable you actually want to read dynamically, rather than hard-coding it: useful when you're selecting between several similarly-named variables based on another value. Note This inside-out resolution applies to a plain $(...) reference typed directly into a text field (a button label, for instance). It does not apply inside a JavaScript-style expression (an Expression node, or an Advanced Expression field): there, $(...) is read as one opaque token that always ends at its first ) , so a literal $( nested inside won't parse as you'd expect. To get the same inside-out effect from within an expression, pass the string through the parseVariables(...) function instead, see Expression functions and operators reference . Nesting inside a variable's value Separately, a variable's own stored value can itself contain a $(...) reference. When something reads that variable, Buttons resolves the reference inside the stored value too, not just the reference you used to look the variable up in the first place. This matters because it means a variable doesn't have to hold a static, final answer: it can hold a reference to something else, and stay current as that something else changes. Buttons guards against a variable's value referring back to itself, directly or through a chain, so a genuine circular reference doesn't hang or crash: instead, wherever that variable is used, you'll see the literal unresolved $(...) reference as text rather than a value. Where to go next Understand variable scope . Use variables in controls and expressions .
