title: Whether should IDBObjectStore.transaction.oncomplete be necessarily used after the IDBDatabase.createObjectStore?
body: <p>I was reading this article from MDN: <a href="https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB" rel="nofollow noreferrer">Using IndexedDB</a>.</p>
  
  <p>There are 2 examples which both create a new object store and add data after creation.</p>
  
  <p>The first example use <code>IDBObjectStore.transaction.oncomplete</code> to make sure the store creation is finished before adding data.</p>
  
  <pre><code>var objectStore = db.createObjectStore("customers", { keyPath: "ssn" });
  // Use transaction oncomplete to make sure the objectStore creation is 
  // finished before adding data into it.
  objectStore.transaction.oncomplete = function(event) {
    var customerObjectStore = db.transaction("customers", "readwrite").objectStore("customers");
    customerData.forEach(function(customer) {
      customerObjectStore.add(customer);
    });
  };
  </code></pre>
  
  <p>However, when I looked at the following example, it made me a little confused:</p>
  
  <pre><code>var objStore = db.createObjectStore("names", { autoIncrement : true });
  customerData.forEach(function(customer) {
    objStore.add(customer.name);
  });
  </code></pre>
  
  <p>As you can see the data is added without a transaction, thus, in theory, the second example would cause some problem while trying to add data before object store is ready.</p>
  
  <p>Surprisingly, both of 2 examples works</p>
  
  <p>I wonder which one should be preferred and why it is preferred. Is using a transaction really necessary?</p>