Skip to content

In JavaScript, 'true' == true is false, truthy truth

Updated: at 02:12 PM

Somehow, I had thought that in JavaScript that if I said ‘true’ == true that a string conversion to bool would happen on the left side of the comparator and that the == instead of the truthy === would do a type conversion for me.

Apparently not.

So, for now on, all my JavaScript will look like this when I’m saving off a boolean that I collect in string form.

 var donationConfirmed = 
  $('#RegisterUserInfoLoggedIn_DonationConfirmed').
      val().toLowerCase() === "true";

Happy to hear why I’m wrong here but I don’t think I am.

Check out the ORM (Object Relational Mapper) PRISMA. The database access method I use in all my projects