Because you’re using getElementsByTagName() it returns an array of all tags that it finds, even if there is only 1 item, it will still be put in to an array. Some other methods like getElementsByClassName() work in the same manner.
However, there are yet others that will return a single result element, for example getElementById().
The way this is useful is if you wanted to iterate through a set of elements, e.g. let’s say you have the following HTML:
<ul>
<li>This is list item 1</li>
<li>This is list item 2</li>
<li>This is list item 3</li>
</ul>
You can iterate through all the list elements like so:
var listElements, i, length;
listElements = document.getElementsByTagName("li");
length = listElements.length;
for (i = 0; i < length; i++) {
//do something with listElements[i]
}
In AJ’s case he was initialising 3 vars all on the 1 line instead of separate lines. You separate the variables names with a comma.
And you don’t have to assign the variable a value initially.
Think of your RAM as a huge pile of pidgeon holes that can store data as variables and their values.
When you type var myVar; without giving myVar an initial value, what you are doing is giving one of the pidgeon holes in your RAM a name myVar but not actually putting a value in the pidgeon hole. So initially it will be set to null until you assign a value to myVar elsewhere in your code.