This code:
var divs = document.getElementsByTagName("div"),
j=5,
i=0;
Is the same as this:
var divs = document.getElementsByTagName("div");
var j=5;
var i=0;
It creates 3 variables:
- Variable div containing all div elements on the page
- Variable j containing the value 5
- Variable i containing the value 0
The reason typeof returns 'object' is because the typeof operator in JavaScript is messed up. It simply returns 'object' for most object-based entities, which include Arrays and NodeLists.
To answer your original question, both the return value from document.getElementsByTagName and document.querySelectorAll are NodeList. This means you will not be able to mutate them, unlike arrays. Furthermore, the value returned by document.getElementsByTagName is a live node list, which means it always reflects the current state of the DOM.
To clarify:
var liveNodeList = document.getElementsByTagName('div');
var nodeList = document.querySelectorAll('div');
console.log(liveNodeList.length, nodeList.length); //Should output the same value twice
document.body.appendChild(document.createElement('div')); //Add a new div to the DOM
console.log(liveNodeList.length, nodeList.length); //Now, the live node list length should be one more since it updated to reflect the DOM state
try{
nodeList.push('test');
}catch(e){
console.log('NodeLists may not be mutated');
}