title: why does push function error out on array of objects?
body: <p><a href="https://i.stack.imgur.com/1SMmP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1SMmP.png" alt="enter image description here"></a>I am trying to use the .push method in javascript but it errors out and I do not understand why. </p>
  
  <pre class="lang-js prettyprint-override"><code>var sc = [];
  localStorage.setItem("score_history", JSON.stringify(sc));
  localStorage.setItem("perfect_score", 0);
  
  function scoreinlocalstorage(perfect_score, winner_score, winner_name) {
    var score_history = JSON.parse(localStorage.getItem("score_history"));
    if (perfect_score &lt; 10) {
      var entry = JSON.parse('{ "name": ' + '"' + winner_name + '", "score": ' + winner_score + "}");
  
      if (winner_score == 24) {
        var new_score = ParseInt(perfect_score);
        new_score += 1;
        localStorage.setItem("perfect_score", new_score);
      }
  
      score_history.push(entry);
  </code></pre>
  
  
  
  <p>Any ideas?</p>
  
  <p>Edit: I have found the error. It has something to do with the way the if statement if handled. </p>
  
  <pre><code>enter code here
  document.addEventListener("DOMContentLoaded", function(){
  if(localStorage.getItem("perfect_score") == null ||  
  localStorage.getItem("score_history") == null){
      var sc = [];
      localStorage.setItem("score_history",JSON.stringify(sc));
      localStorage.setItem("perfect_score",0);
  }....
  enter code here
  var s=[];
     localStorage.setItem("score_history",JSON.stringify(s));
  
      var score_history = JSON.parse(localStorage.getItem("score_history"));
      var perfect_score = localStorage.getItem("perfect_score");
  
      if(perfect_score &lt; 10){
  
  
          var entry = JSON.parse('{ "name": '+'"'+winner_name+'", "score": '+winner_score+"}");
  
  
          if(winner_score == 24){
              var new_score = parseInt(perfect_score);
              new_score += 1;
              localStorage.setItem("perfect_score", new_score);
          }
  
          score_history.push(entry);
  </code></pre>
  
  <p>Previously, looking at the log, score_history would return a string, but now it simply returns '[]' which IS correct.
  So now my question is, why doesn't my program like the way it is handled in the if statement?</p>