I have a bunch of javascript functions, that trigger upon button clicks. So assuming we have two button s that trigger two methods such as:
var universal = false;
var collection = Array(); // assume it has 5 data elements( 0...4) upon page load
function next()
{
if(universal)
addToArray();
// do whatever else
}
function addToArray()
{
console.log(collection);
// perform some DOM calls,that simply Hide/change position of elements
var newElement = 'some info';
collection.push(newElement);
}
In the above addToArray() function, it is called upon when 'next' button is clicked and the universal variable is set to true. At this point we enter, addToArray() method and a console.log is invoked to check out 'collection'.
This, at any given point, should be not more than 5 elements since addToArray will eventually add an element to collection but not right at the start. However, the console.log shows that collection has the new element added, which was actually supposed to be added during the addToArray method() not right off the bat.
I know this sounds really goofy, but this is what I am getting. I am trying to understand if asynchronous behavior has anything to do with it.