So there are two separate things going on here:
- variables are being declared;
- variables are being assigned a value.
the declaring part of the process is pretty simple:
is all that is required to declare a variable. That’s it. Once declared, it exists, doesn’t need to be re-declared.
Now the second part is where that variable is assigned a value. That can look like this:
a = 7;
That assigns the integer
7 into my variable
a (or it initializes
a with the value of
7). The two CAN be combined, but only the first time - once a variable has been declared, remember, it doesn’t need to be done again. So we can combine them like this:
var a = 7;
This sets aside the variable’s space (declares the variable), and assigns it a value (initializes the variable). We can do that with both
b, works fine.
Later on, however, you are being told to assign the value of
a. It’s an assignment, and
a has already been declared (the variable name already exists). So how do we assign a value? Look above, where I set it to 7. We can set it to anything, even the value of another array:
var foo = "one";
var bar = "two"
// later on, I want to set foo to the value of bar:
foo = bar; // <-- I didn't use var or anything, as they both already exist!