title: Is JavaScript in the DOM Async or Synchronous Code?
body: <p><strong>The original question was: "Vanilla javaScript DOM queries. How to make sure async code has completed in front-end before continuing?"</strong></p>
  
  <p><strong>but I changed the title, so that it would be more useful to search queries, and show what info is actually being given in the answer.</strong></p>
  
  <p>You'll notice that, based on the code that I provided, I thought that DOM manipulations were asynchronous.  The answers pointed out that it is not.</p>
  
  <hr>
  
  <p>If code like this is asynchronous:</p>
  
  <pre><code>let elements = document.querySelectorAll('div');
  </code></pre>
  
  <p>Then, how do you make sure that all of the 'div' elements have been stored to the variable 'elements' before looping over them?</p>
  
  <pre><code>let elements = document.querySelectorAll('div');
  //how do you know that all of the elements will 
  //have been retrieved in time to run this for loop:
  for(let i = 0 ; i &lt; elements.length ; i++) {    
      let div = elements[i];    console.log(div);   
  }
  </code></pre>