Here we go again,let's clean up this mess.
So....we have 2 types equality operators
== called equality operator
=== called identity operator
Most important to remember is that equality and identity operators are checks is both value are equals ,but identity operator checks more strictly (without using autoconversion so it means both value need to be of the same type (except NaN)
Equality operator checks
- for strings, numbers and booleans
1 == "1" will return true
1 == true will return true (Because boolean can represent true as 1 an false as 0)
- For arrays and object
Identity operator checks
- not only values as Equality, doesn't use automatic conversion ,so both values have the same value and the same type (if not are not equal) ,so
= means "assign to"
== means "equal to"
=== means "identical to"
1 ==/=== "1" will return true for equality operator and return false for identity operator because comparison has different type (it applied to 1 == true as well )
x = 5
means 5 is assign to variable x
x == 5
means 5 is equal to x (return will answer on question "Is 5 is equal to x?")
x === 5
means 5 is identical to x (return will answer on question "Is 5 is identical to x?")
If your comparison doesn't work in Java then can be 3 cases:
1) you mispell something in your code
2) you forgot about one of rule written in this post (about difference between == and === and result which will return
3) you forgot about difference between null undefined and NaN (null and undefined issues are explained in previous note