Questions tagged [identity-operator]

The identity operator applies strict comparison on the operands, without doing a type conversion.

The identity operator applies strict comparison on the operands, without doing a type conversion. This means that 'true' will be returned only if the operands are equal in value and type.

See also:

17 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?
174
votes
12 answers

Why is === faster than == in PHP?

Why is === faster than == in PHP?
coderex
  • 27,225
  • 45
  • 116
  • 170
57
votes
10 answers

What does "===" mean?

I've noticed someone using the PHP operator === which I can't make sense out of. I've tried it with a function, and it corresponds in crazy ways. What is the definition of this operator? I can't even find it in the declaration of PHP operators.
Stefan Konno
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')
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 !==?
18
votes
4 answers

When would JavaScript == make more sense than ===?

As Which equals operator (== vs ===) should be used in JavaScript comparisons? indicates they are basically identical except '===' also ensures type equality and hence '==' might perform type conversion. In Douglas Crockford's JavaScript: The Good…
bryantsai
  • 3,405
  • 1
  • 30
  • 30
15
votes
4 answers

How do I achieve the effect of the === operator in Python?

How do I achieve the effect of the === operator in Python? For example, I don't want False == 0 to be True.
speg
  • 1,959
  • 6
  • 24
  • 34
8
votes
1 answer

id() vs `is` operator. Is it safe to compare `id`s? Does the same `id` mean the same object?

How much can I rely on the object's id() and its uniqueness in practice? E.g.: Does id(a) == id(b) mean a is b or vice versa? What about the opposite? How safe is it to save an id somewhere to be used later (e.g. into some registry instead of the…
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
7
votes
4 answers

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

Possible Duplicate: Javascript === vs == : Does it matter which “equal” operator I use? When would JavaScript == make more sense than ===? What is the difference between below methods in comparing a string with undefined value. var x; …
Exception
  • 8,111
  • 22
  • 85
  • 136
5
votes
2 answers

Why identical operator in php (===) fails with DateTimeImmutable objects?

I have two DateTimeImmtable objects, and expecting them to be identical I am surprised to see they are not. Ie, why is the following false?
hosseio
  • 1,142
  • 2
  • 12
  • 25
3
votes
1 answer

How do you test the identity of Strings in Swift?

Swift, like a few other languages, has an identity operator ===. But it seems like you can't use it against strings: var x = "hello" var y = "hello" if x === y { //ERROR: 'String' does not conform to protocol 'AnyObject' …
user1040049
1
vote
1 answer

Python Identity operators with variables and datastructures

I have the following code: a = [] b = a when I compile the following code I get this: print(b is a) --> True print(b is []) --> False if b = a then shouldn't b is [] return True?
Nant
  • 569
  • 2
  • 10
  • 24
0
votes
1 answer

Numpy arrays and identity operator is

Having a numpy array like x and a slice that includes all its elements as z, why the identity operators gives false, despite the fact that changing the value of any element in z reflects on x and vice versa x = np.array([1, 2, 3, 4, 5]) z = x[:] x…
Osama Hamdy
  • 103
  • 2
  • 9
0
votes
0 answers

Why Python "is" operator gives different result for variable containing same string

When i am trying to compare the identity of two variable containing same string, python gives me different result. msg = "hello world" new_msg = "hello world" print( msg is new_msg ) > False But, msg = "hello_world" new_msg = "hello_world" print(…
1
2