title: Javascript LocalStorage Null Bug
body: <p>I'm saving elements in the localstorage like this (using strict mode):</p>
  <p><code>localStorage.setItem(String(index), JSON.stringify([name, score]));</code></p>
  <p>Then I wrote a method checking if a new score is bigger than the saved ones:</p>
  <pre><code>    // Returns index where to place the score and return -1 if no new highscore
      function isHighScore(score) {
      console.log(&quot;called&quot;);
      for (var i = 0; i &lt; 3; i++) {
          if (localStorage.getItem(String(i)) == null) {
              return i; // No highscore yet at this position =&gt; new Highscore
          }
          else{
              var indexObject = JSON.parse(localStorage.getItem(String(i)));
              console.log(indexObject);
              if(indexObject[1] &lt; score){ // Checking if new score is higher than currently at this index
                  return i; // Returning index if new highscore
              }
          }
      }
      return -1; // checked all entries no new highscore
  }
  </code></pre>
  <p>But I get this following output (after saving example with name=&quot;name&quot; and score= 0):</p>
  <blockquote>
  <p>called</p>
  <p>[&quot;name&quot;, 0]</p>
  <p>null</p>
  <p>Uncaught TypeError: Cannot read property <code>1</code> of null</p>
  </blockquote>
  <p>How can this happen? I'm already checking if the value is <code>null</code> so how can this pass the first if check <code>localStorage.getItem(String(i)) == null)</code>?</p>