From the EDITOR'S NOTES to David Hilbert & Wilhelm Ackermann, Principles of Mathematical Logic (2nd ed : 1937; english transl : 1950), page 168 :
The distinction between variables and constants [...] is sometimes difficult to grasp clearly. It is not always understood that a constant, like a variable, is a symbol,
a linguistic expression, but with the important distinction that a constant has a fixed designation, which remains unaltered throughout the discussion in which the constant appears; whereas a variable designates ambiguously, so to speak, assuming anyone
of a range of values. It would, however, be a grave error to suppose that the distinction between variables and constants reflects a corresponding distinction in the domain of objects to which the variables and constants alike refer. Thus to assert with reference, say, to real number theory that the variables "$x$" and "$y$" designate variable numbers, whereas such constants as "$2$" and "$\pi$" designate constant numbers, would be nonsense; or at least there is no known intelligible theory which could accommodate so odd a notion as that of a variable number.
In mathematical logic, variables are mainly used with quantifiers.
In order to compare with computer science, we can see Zohar Manna, Mathematical theory of computation (1974), where the language of predicate calculus [page 77-on] is used for the description of programs.
We have [page 82] the usual definition of well-formed formula :
(c) If $v_i$ is a variable and $A$ is a wff, then $\forall v_i A$ and $\exists v_i A$ are wffs.
Then he use variables to formalize flowchart programs [page 161] :
We distinguish among three types of variables (grouped as three vectors): (1) an input
vector $\overline{x} = (x_l, x_2,. . . , x_a)$, which consists of the given input values and therefore never changes during computation; (2) a program vector $\overline{y} = (y_1, y_2, ..., y_b)$, which is used as temporary storage during computation; and (3) an output vector $\overline{z} = (z_1, z_2, ... z_c)$, which yields the output values whe computation terminates.
Finally, the assignment function is introduced [page 164] :
Note that $(y_1, y_2) \leftarrow (0, x_1)$ means that $y_1$ is replaced by $0$ and $y_2$ is replaced by $x_1$ [...]. In general, we shall use the notation $(y_1, y_2, ..., y_n) \leftarrow (g_1(\overline{x}, \overline{y}), ... g_n(\overline{x}, \overline{y}))$ to indicate that the variables $y_i, 1 \le i \le n$, are replaced by $g_i(\overline{x}, \overline{y})$ simultaneously; that is, all the $g_i$'s are evaluated before any $y_i$ is changed. For example, if $y_1 = 1$ and $y_2 = 2$, the assignment $(y_1, y_2) \leftarrow (y_1 + 1, y_1 + y_2)$ yields $y_2 = 3$, not $y_2 = 4$.
In computer languages, the instruction $x=x+1$ (if allowed) is not a numerical identity; there are no reasonable meanings of the concept "number" that may make sense of a statement like : "a number is equal to itself plus $1$".
In the context of computer languages, when we use the instruction
$x_1 \leftarrow x_1 + 1$
the symbol $x_1$ is not a variable: it is a constant.
It is the name of a storage location (memory array or register), like the square on the tape of a Turing machine, and the simple statement above is a "complex" instruction specifiying the following operation :
i) read the content of the storage location ("cell") $x_1$, (say $n$);
ii) add $1$ to that number;
iii) erase the content of the cell $x_1$;
iv) write the number $n+1$ into the cell $x_1$.
During the context of the execution of the program, the name $x_1$ will not change its denotation (the "cell").
The above process can be described as follows: we have a box with six eggs inside and we pull out the eggs from the box. Then we add a new egg and finally we put the seven eggs in the box :
the box does not change, his content has changed.