Is there a detailed definition of the concept of a 'variable', and why do we use them as such? I've noticed that recently I've been struggling with some aspects of our logical ideas in Algebra and they seem to revolve around the idea of the true concept of a 'variable'. I mean this in the most simple use of the word, as a form of 'placeholder'. Something like $x_i$ has another variable in it's index, and provides other problems, if there is $x_i$ and $x_1$ we can thing of $x_i$ as a more general form of the latter, if we have variables $x$ and $y$ we can call them 'separate variables' in the case of $x_i$ and $x_1$ we could have $i=1$ in which case $x_1$ and $x_i$ are not separate?
Another thing that I would be interested to know is based around the way we talk about them, for example:
We have an expression for example:
$3x+1$
We can talk about this in a general way, what values do we expect this quantity to take for differing values.
We might write $y=3x+1$, we then write something like
'if $x = 3$'
and we'll say $y = 10$ but y is being used as a general term and we jump between these 'contexts', this seems odd to me, I understand the idea but it seems strange all the same.
In the same way, having
$3x+1=10$ is a statement and we can talk about it generally where $x$ is no particular number, and even quantify over it using quantification logic, but again we may write
if '$x = 3$' and we will write then 10=10 and the statement is true.
It seems strange to use this notation '$x=...$' and to use 'if' or 'when' because are these 'variables' really changing or are we really just expressing the structure for where there is a specific number instead of a placeholder?
It begs the question, is it just a placeholder for 'some' value, or does it almost represent something that is somehow changing by itself (how can it do so on a piece of paper), if it is simply a place holder, saying 'when $x=$' or if '$x=1$' seems strange to me, would we not perhaps best define some kind of 'replacement' operation instead of this kind of 'assignment'? Does $x$ somehow have a value at all times? Or are we constantly jumping from context to context? Where each context is hypothetical?Can $x$ somehow represent multiple values at once.
If we talk about $x=1$
Can we also write $x+1=2$ and have $x$ as a proxy for $1$
and hence have $a_x$=$a_1$ for all values?
 A: In the way that they are used and understood in first order logic, a variable is nothing more than a piece of language. Variables helps us form mathematical sentences, so in a very literal sense, a variable is just a symbol, like the letters in a language. Variables are the core of formal mathematics, and they let us make general claims about what sorts of things are true.
A formula is a string of symbols in a formal language, one which is formed in accordance with the grammar of the language (usually called formation rules). For example, "$x\neq 3$" is a formula, because we understand the string to be asserting something, namely that "the object $x$ is not $3$". Without context though, the variable $x$ is sort of meaningless. It could be almost anything: a number, a set, a function, a person? Formally, $x$ is said to be a free variable of the formula "$x\neq 3$", because it has not been bound by a quantifier. Whether or not a variable is free or bound is dependent on the formula itself, it's not dependent on what other assertions are floating around; each formula categorizes its own variables.
Quantifiers are used in formal logic to bind a variable, and give it meaning by placing it in a context. For example, the sentence "$\forall x, x=3$" has a distinct and unambiguous meaning. It is saying "every object is $3$". This is false in basically every axiomatic system, but it is unambiguously false. We don't have to wonder about what $x$ is, because it's not really anything, it's just a formal way to say "object". We can also use different variables to talk about (possibly) different objects.
A sentence is a formula that has no free variables, they are typically formed by binding all the variables with quantifiers. A mathematical sentence has a totally unambiguous interpretation, it's either true or false. Whether a sentence is true or false depends on the surrounding axioms of the formal system. For example, the sentence "$\forall x, \exists y, y=x+1$" simply means "given any object ($\forall x,$), there is another object ($\exists y,$) that is $1$ more than the first ($y=x+1$)". If the objects we're talking about are integers, this is true, and it follows from the axioms of the integers.
Axioms are sentences which are implicitly assumed to be true. There a few ways to think of axioms. The platonic interpretation is that an axiom is something that is so simple and self evident that it absolutely must be true. Less rigidly, you could instead think of them as invisible premises, a way to not have to say "if so and so holds, then..." over and over. More intuitively though, axioms are what we use to describe what all these "objects" are. Each system of abstractions will have its own axioms, and mathematics is essentially the study of how to use axioms (simple truths) to get a thorough understanding of how an abstract system works.
A definition is a formal way to give a name to a specific object that you already know exists. That object could be a number, a function, a relation, etc, so long as you already know it exists. If we're being perfectly formal, the thing you're defining should almost always be a constant. For example, if you want to talk about the function that is associated with $y=3x+1$, what you really want to talk about is its graph, and what that graph (as an unchanging object) looks like. The symbols we use for definitions (like $3, e, \pi$) are sometimes the same as the symbols we use for variables. Because we only have so many symbols, that's unavoidable. When we use a variable to form a definition though, that symbol should stop being categorized as a variable, since it no longer serves the same linguistic purpose. For instance, it makes sense to say "$3\neq 4$", but it's absurd to write "$\forall 3, 3\neq 4$" because $3$ is a constant, not a variable.
The issue with variables in less formal approaches is that they tend to get merged with axioms and definitions in ways that are hard to untangle. For example, if we assert $y=3x+1$, what is this? If $x$ and $y$ are variables, then it can't be an axiom, because variables are supposed to be totally featureless elements of a language. Usually when something like this is done, the presenter is asking "if this is true, what else is true?" in which case it does actually amount to an axiom (or a premise, no difference). This is formally valid, but only if you stop considering $x,y$ to be variables; now they're just poorly defined constants. This is usually what people think about variables, a constant where you don't know what it is, but that's more akin to incompleteness. The formal system is unambiguously saying "this is a constant, not a variable", but it's not giving you enough information to figure out what the constant is actually supposed to be. This feature is useful when generalizing through deduction, but it is confounding to think about an "intentionally ambiguous constant", so people just call them variables (even though, technically, they are not).
A: There is no single working definition of what a variable is. Depends on context.
When considering polynomials in algebra, for example, $p(x)= x^2 -x -1$, the "$x$" in this expression is only a notational convention. It does not really exist. Polynomials are defined as finite sequences of numbers, so $p(x)$ as described above, is $p=(-1,-1,1)$.
When considering polynomials as functions in calculus, that "$x$" has meaning in that expression, and it actually plays the role of a "placeholder" as you mentioned. Since it is a placeholder, we can rename it at will without changing the meaning, so for example we could write $p(-|-)= (-|-)^2 - (-|-) - 1$, where "$-|-$" is a symbol I just invented.
Now consider the final case of "no particular context". Consider the expression $x=1$. This "$x$" is not a notational convention and not a placeholder, since I can't put $5$ in the place of $x$. So what is it? It is usually called a free variable, and is an interesting topic for you to search about.
Note that placeholders are usually called bound variables in contrast with free variables, and in the algebraic-polynomials case, the "variables" are called indeterminates.
A: 
the concept becomes more complex when we consider things such as
(3), this is technically a placeholder for a simple number

Suppose that $f:\mathbb R \to \mathbb R$ is a function. Then $f(3)$ is a number. It is the output of the function $f$ when the input is $3$. I would not call it a placeholder or a variable. It is simply a number.
In fact, I typically avoid the term "variable" entirely. In my mind, there is no such thing as a "variable". It is not a term that has a precise definition (except perhaps in parts of more advanced math, which we need not bother with when understanding high school algebra).
So for example, I will say things like:
If $x$ is a number and $3x + 1 = 10$ then $x = 3$.
Here, $x$ is not a "variable", it is simply a number. Sometimes I might call it an "unknown number", or "unknown" for short. Of course, its value is only unknown until we recognize that $x = 3$, then its value is known.
