Questions tagged [object-comparison]

66 questions
1458
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
  • 21,555
  • 10
  • 42
  • 73
768
votes
26 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
  • 19,826
  • 28
  • 77
  • 115
98
votes
6 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
  • 11,077
  • 20
  • 84
  • 119
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
  • 25,711
  • 35
  • 110
  • 162
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: