title: javascript strange comparison of strings
body: <p>I have an ajax function that sends an email to somewhere and receives a response from the server from a json object with type = either success or error</p>
  
  <pre><code>$("#submit_btn").click(function(event) { 
      event.preventDefault();
  
      var post_data = {
          'email': $("#email").val()
      };
      $.post( "sendEmail.php", post_data ).done(function(response){
          if(response.type == 'success'){
              $("#sentmail").fadeIn("slow")
              setTimeout(function(){
                  $("#mail").val("Enter your email here");
  
                  $("#sentmail").fadeOut("slow")  
              },3000);
          }
          else{
              $("#sentmailfail").fadeIn("slow")
              setTimeout(function(){
                  $("#mail").val("Enter your email here");
  
                  $("#sentmailfail").fadeOut("slow")  
              },3000);
          }
      },"json")
  });
  </code></pre>
  
  <p>The interesting part is that if I <code>console.log(response)</code> I get for instance <code>{"type":"success","desc":"something"}</code> and then straight after that <code>console.log( (response.type == "error") ) // TRUE</code></p>
  
  <p>if I take the consoled log from response and assign it to a variable for instance <code>a = {"type":"success","desc":"something"}</code> then <code>a.type == "error"</code> is false.</p>
  
  <p>Can someone explain this?</p>