What is difference between "==" and "===" (javascript)?


Theoretically i understand that, but practically?


Well, i was writing a script the other day, and i got something in return, which i assumed was a Boolean, but it was a string, and i was using 3 equal signs, and i couldn't figure out what was wrong, my if statement looked something like:

if (obj['Response'] === true){
  /* do something */

turns out, i got a string true, which means this if statement doesn't doesn't run (i got my object from a json i fetched from the internet)

So practical? Is the data type relevant, do i need to use 2 or 3 equal signs? And i am sure my datatype is correct if i use 3 equal signs?


= is for assignment. This means that var myBool = "true";, and that's it.

== is checking for the same value, but not the same type. So if you are checking if myBool = true orĀ  myBool = "true", it will return true.

=== is checking for the same value and type which means myBool = "true" will return true, but myBool = true will not.


If you want to mess with the big dogs, try this Stack Overflow question. They're a lot meaner than this forum though so be careful.


Thanks for your answers guys. I understand this almoust, but need some extra time to understand at all 100%. I asking this question also - because in different online tutorials they use == and === at the same palce and subject. For example explaining if, if else and switch so on.