Having an object to store data.
var store = {
elements: [],
eventsEnabled: true,
addElement: function(element) {
this.elements.push(eleme
JavaScript is single-threaded. A function cannot be interrupted, so you can be sure each function block will complete before another begins.
(However, if a function makes an asynchronous call, other functions may execute before the asynchronous operation starts. That doesn't happen in your code, though, that I can see, besides the setTimeout
calls, and you can be sure those will execute in the correct order.)