The equality operator applies comparison between the operands. Different languages may implement varying degrees of strictness, such as type comparison in addition to value.
Questions tagged [equality-operator]
79 questions
5649
votes
48 answers
Which equals operator (== vs ===) should be used in JavaScript comparisons?
I'm using JSLint to go through JavaScript, and it's returning many suggestions to replace == (two equals signs) with === (three equals signs) when doing things like comparing idSele_UNVEHtype.value.length == 0 inside of an if statement.
Is there a…

bcasp
- 57,397
- 4
- 19
- 15
1707
votes
2 answers
Difference between == and === in JavaScript
What is the difference between == and === in JavaScript? I have also seen != and !== operators. Are there more such operators?

Shiva
- 18,235
- 4
- 20
- 9
296
votes
15 answers
Are == and != mutually dependent?
I'm learning about operator overloading in C++, and I see that == and != are simply some special functions which can be customized for user-defined types. My concern is, though, why are there two separate definitions needed? I thought that if a == b…

BarbaraKwarc
- 2,667
- 2
- 14
- 17
174
votes
12 answers
98
votes
10 answers
Comparing numpy arrays containing NaN
For my unittest, I want to check if two arrays are identical. Reduced example:
a = np.array([1, 2, np.NaN])
b = np.array([1, 2, np.NaN])
if np.all(a==b):
print 'arrays are equal'
This does not work because nan != nan.
What is the best way to…

saroele
- 9,481
- 10
- 29
- 39
61
votes
2 answers
Why is operator!= removed in C++20 for many standard library types?
According to cppreference, std::type_info::operator!= gets removed with C++20, however, std::type_info::operator== apparently remains.
What's the reasoning behind? I might agree on comparing for inequality being meaningless, but then comparing for…

Aconcagua
- 24,880
- 4
- 34
- 59
52
votes
7 answers
Why does new String('hello') === new String('hello') evaluate to False?
Why does the following statement return false in JavaScript?
new String('hello') === new String('hello')

santosh kore
- 976
- 1
- 12
- 21
40
votes
6 answers
JavaScript - === vs == operators performance
A few weeks ago, I have read this thread Is < faster than <=? about comparison operators in C. It was said that there is no difference in the performance between < and <= as they are interpreted as same/similar machine commands.
At the same time, in…

gotqn
- 42,737
- 46
- 157
- 243
24
votes
3 answers
why is not (123 == 0123) in java?
I am developing an application in Android using Eclipse. I wrote the following code and in tests the first and third "if" block is not reachable. Why?
When I add a leading zero to a number, the equal operator returns false.
int var = 123;
if (var ==…

Bob
- 22,810
- 38
- 143
- 225
21
votes
4 answers
What is difference between == and === in kotlin
What is the difference between the comparison operators == and === in Kotlin?
class A {
var foo = 1
}
var a1 = A()
var a2 = A()
println(a1 == a2) // output false
println(a1 === a2) // output false
a1 = a2
println(a1 == a2)…

SergeyBukarev
- 1,478
- 1
- 12
- 19
21
votes
9 answers
Using the equality operator == to compare two strings for equality in C
int main (int argc, **argv)
{
if (argv[1] == "-hello")
printf("True\n");
else
printf("False\n");
}
# ./myProg -hello
False
Why? I realize strcmp(argv[1], "-hello") == 0 returns true... but why can't I use the…
user402642
19
votes
2 answers
Difference between == and === in JS
Possible Duplicates:
Difference between == and === in JavaScript
Javascript === vs == : Does it matter which “equal” operator I use?
What's the difference between == and ===? Also between !== and !==?

jslearner
- 21,331
- 18
- 37
- 35
12
votes
4 answers
Comparing size_t to -1
Note: it has been suggested that this question duplicates Can I compare int with size_t directly in C?, but the question here specifically asks about comparing size_t with a negative value. For this reason, it should be re-opened. (And besides, it…

fearless_fool
- 33,645
- 23
- 135
- 217
11
votes
1 answer
Why is b[2] false?
string s;
bool b[] = {s=="", s==s.c_str(), s.c_str()==""};
sets
b[] = {true, true, false};
why is b[2] false?
If A==B and A==C, should that not imply B==C?

NoComprende
- 731
- 4
- 14
10
votes
4 answers
What is the difference between Java's equals() and C++'s operator ==?
In a question regarding the use of typeid is C++, I suggested it could be used to compare types in objects comparison. I haven't seen it done much, but I had Java's equals in mind.
Looking into Java a bit more, this seems to be the case: Some say…

Eran
- 21,632
- 6
- 56
- 89