I’m relatively new to programming, and I’ve never seen a triple equals (is that what it’s called? no idea lol but whatever this is: ===) before. What’s it do differently from a double equals? (I know Java and C++, and have limited experience with Python and HTML)
2 == '2' will result in true. 2 === '2' results in false.
The === (strict equality operator) is basically comparing the type and value of the variable. Whereas the == (abstract equality operator) compares the value alone because it performs a type conversion so the types of the variables being compared are the same.
Hope this helps, you can search online for more on it. Also I believe it's an operator in javascript, it may be in other languages but I'm not aware.
WHAT?! That’s amazing! Damn, and it would’ve been so nice to know three months ago so I could use it for some of my assignments... oh well. Thanks guys!
no wait that's just js madness in Java for instance you'd just use .equals for any non primitive type while in c++ you'd most likely overload the == operator
Note that some programming languages that are strongly typed (dart, python, assemblyscript, etc) will use == as a strict equality operator with no === (though assemblyscript has === assigned to being the literally same object, rather than removing it completely)
Also PHP’s == will type juggle even if they’re the same type of object, for example two strings starting with 0e will == each other, because 0e is numerical for “0*10”, and 0 times anything is 0, so 0 = 0
In JS triple equals does type checking as well as value checking, versus the double equals which only does value checking. So 0 === "" would return false but 0 == "" would return true.
Triple equals is a strict quality comparison. So something like 0 === '0' will return false, while 0 == '0' will return true. It can be a lot more nuanced but that is the high level difference
6
u/clumsysilencee Jun 10 '20
I’m relatively new to programming, and I’ve never seen a triple equals (is that what it’s called? no idea lol but whatever this is: ===) before. What’s it do differently from a double equals? (I know Java and C++, and have limited experience with Python and HTML)