title: Javascript function returns undefined value, even though the variable has been defined and fetched from IndexedDB
body: <p>So, I am using IndexedDB, which has some data. I wanted to search through it and once there's a match, I returned a corresponding data. Here's the code:</p>
  
  <pre><code>function code1(sname){
          var db;
          var request1 = indexedDB.open("footballDatabase",1);
          request1.onsuccess = function (evt) {
              db = request1.result;
              var objectStore = db.transaction("teamsData").objectStore("teamsData");
              objectStore.openCursor().onsuccess = function(event) {
                  var cursor = event.target.result;
                  if (cursor) {
                      var name = cursor.value.name;
                      if(sname === name){
                          var code = cursor.value.code;
                          console.log(sname + " " +code);
                          return code;
                      }else{
                          cursor.continue();
                      }
                  }
              };
          }
      }
  </code></pre>
  
  <p>This is the function call:</p>
  
  <pre><code>alert(code1("Chelsea FC"));
  </code></pre>
  
  <p>The console shows everything properly when I logged the results. But when returned, it shows undefined. 
  I know that undefined in JS means, the variable hasn't been properly initialized before. But in this case, it is, because it logs the same variable just alright.</p>
  
  <p>I know, I did something wrong, I just can't figure out what. Hope you guys can help me out. </p>