Questions tagged [object-comparison]

56 questions
1245
votes
10 answers

Object comparison in JavaScript

What is the best way to compare objects in JavaScript? Example: var user1 = {name : "nerd", org: "dev"}; var user2 = {name : "nerd", org: "dev"}; var eq = user1 == user2; alert(eq); // gives false I know that two objects are equal if they refer to…
spankmaster79
  • 19,078
  • 10
  • 38
  • 69
680
votes
23 answers

What is the difference between == and equals() in Java?

I wanted to clarify if I understand this correctly: == is a reference comparison, i.e. both objects point to the same memory location .equals() evaluates to the comparison of values in the objects
brainydexter
  • 17,648
  • 25
  • 70
  • 108
90
votes
5 answers

Checking object equality in Jasmine

Jasmine has built-in matchers toBe and toEqual. If I have an object like this: function Money(amount, currency){ this.amount = amount; this.currency = currency; this.sum = function (money){ return new Money(200, "USD"); …
Dan
  • 10,523
  • 17
  • 77
  • 117
63
votes
7 answers

Python: Why does ("hello" is "hello") evaluate as True?

Why does "hello" is "hello" produce True in Python? I read the following here: If two string literals are equal, they have been put to same memory location. A string is an immutable entity. No harm can be done. So there is one and only one…
Deniz Dogan
  • 23,833
  • 33
  • 104
  • 154
45
votes
2 answers

How to compare two object variables in EL expression language?

I am creating a drop down list of all languages. The default language selection for the list will be determined by information added by the user: