title: 'Uncaught SyntaxError: Unexpected token u' when using JSON.parse
body: <p>I'm using JSON.parse as a simple database on my computer with LocalStorage.
  It works smoothly until I'm doing the check of this "database";
  heres the code for entering information to LocalStorage:</p>
  
  <pre><code>var users = JSON.parse(localStorage.registeredUsers);
  users.push({username:name, password:userpass, connected:false});
  localStorage.registeredUsers = JSON.stringify(users);
  </code></pre>
  
  <p>and when I', having the check of that registeredusers I get the error "Uncaught SyntaxError: Unexpected token u":</p>
  
  <pre><code>var users = JSON.parse(localStorage.registeredUsers);
          if(users[userindex].connected)
          {.........}
  </code></pre>
  
  <p>The error points to the line with JSON.parse.
  I tried to figure it out with some similiar topics but couldnt find the way.</p>
  
  <p>The code that I push into the array of localstorage:</p>
  
  <pre><code>function regBtn(event)
      {
          event.preventDefault();
          name=document.forms["regform"]["username"].value;
          userpass=document.forms["regform"]["password"].value;
          localStorage.username=name;
          localStorage.password=userpass;
          if(!(localStorage.registeredUsers))
          {
              localStorage.registeredUsers = '[]';
          }
          var users = JSON.parse(localStorage.registeredUsers);
          users.push({username:name, password:userpass, connected:false});
          localStorage.registeredUsers = JSON.stringify(users);
          $('#mainContent').load('HomePage.html');        
      }
  </code></pre>