title: SyntaxError: Unexpected token u
body: <p>I always seem to get the error SyntaxError: Unexpected token u when i run my code, i have looked through other answers but none have helped me.
  I'm using angularjs and passing in the id from a json array.</p>
  
  <pre><code>var fav=[];
  if($window.localStorage['fav']){
      $scope.fav = JSON.parse($window.localStorage['fav']);
  } else {
      $scope.fav = [];
  };
  
  $scope.togglefav = function(id) {
  var a = JSON.parse($window.localStorage['fav']);
    if (a.indexOf(id) == -1){
      fav.push(id);
      console.log(fav);
      $window.localStorage['fav'] = JSON.stringify(fav);
      }
      else{
        a.splice(id, 1);
        $window.localStorage['fav'] = JSON.stringify(a);
        console.log(a);
      }
  };
  </code></pre>
  
  <p>My current localstorage is empty but the if statement at the should resolve any issue by creating a new array if one isn't  available.</p>