0

What is the difference between == and ===?

24th Jan 2017, 9:37 AM
Ahmed Abd Elazeem
Ahmed Abd Elazeem - avatar
2 Answers
+ 2
'==' means equality. It will make the operands true, if they are similar as per Java's library. Take this example: 1=="1". Here 1 and "1" serve as operands, and '==' serves as the operator. This would return the value as true. In another example, 1==2, the value returned would be false. '===' refers to strict equality. The operands have to be strictly true. That means the above example would not work. 1==="1" would return as FALSE in this case. 1===1 would return true. This is just a very basic example. When objects are included things are taken up a notch. If you understand the concept on a very basic level, you should be able to gradually apply that to concepts of higher learning. The same theory applies to inequalities of both the regular and strict type. These are denoted with != and !== respectively. Strings are compared using standard lexiographical ordering and using Unicode values. Lexiographical ordering refers to the syntactical order of elements (objects, values, delimiters..) This same ordering is how one determines parsing. These two components are crucial in the development of COMPILERS.
24th Jan 2017, 10:33 AM
Abe Shudug
Abe Shudug - avatar
+ 1
I think == converts the two values to the same type, before it checks if the values are equal. So, 0 == 0 is TRUE, but also 0 == '0' is TRUE === is more strict and also checks if the two values that are compared are of the same type. So, 0 === 0 is TRUE, but 0 === '0' is FALSE Hope that helps a bit
24th Jan 2017, 10:22 AM
man of the hour
man of the hour - avatar