# Object Equality

**URL:** <https://forum.codewithmosh.com/t/object-equality/17518>\
**Category:** JavaScript\
**Created:** [January 7, 2023, 1:15pm UTC](https://forum.codewithmosh.com/t/object-equality/17518 "2023-01-07T13:15:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![YuriAmancio](https://avatars.discourse-cdn.com/v4/letter/y/e47c2d/32.png) [@YuriAmancio](https://forum.codewithmosh.com/u/YuriAmancio)\
**Post date:** [January 7, 2023, 1:15pm UTC](https://forum.codewithmosh.com/t/object-equality/17518/1 "2023-01-07T13:15:24Z")

</div>

Hi all,

I’m doing exercise create Equality related to Objects in JavaScript course.

The exercise is to create two objects with the same properties using a factory function:

```auto
function CreateAddress(street, city, zipCode){
  this.street = street;
  this.city = city;
  this.zipCode = zipCode;
}

const address1 = new CreateAddress('a', 'b', 2477798);
const address2 = new CreateAddress('a', 'b', 2477798);

```

and then to create a function to check if the two objects are referecing the same address in memory.

```auto
function areSame(addressObj1, addressObj2) {
  return addressObj1 === addressObj2
}

//output: false

```

my question is more about the function syntax than the concept of the exercise.  
If I use:

```auto
function areSame(addressObj1, addressObj2) {
if (addressObj1 === addressObj2)
return;

//output: underfined

```

What is going wrong on the second syntax? Thanks

---

<div class="post-metadata">

**Author:** ![SAM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sam/32/167_2.png) [@SAM](https://forum.codewithmosh.com/u/SAM)\
**Post date:** [January 7, 2023, 5:04pm UTC](https://forum.codewithmosh.com/t/object-equality/17518/2 "2023-01-07T17:04:54Z")

</div>

With

> [@YuriAmancio](#):
>
> `return addressObj1 === addressObj2`

your function returns a boolean result (`true` or `false`).

With

> [@YuriAmancio](#):
>
> `return;`

your function returns nothing, the result of it is `undefined`.

If you for what ever reason want to use an `if` you need to explicitly return `true` or `false`:

```auto
function areSame(addressObj1, addressObj2) {
if (addressObj1 === addressObj2)
   return true;

return false;

```

---

<div class="post-metadata">

**Author:** ![maverick](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@maverick](https://forum.codewithmosh.com/u/maverick)\
**Post date:** [January 8, 2023, 3:46am UTC](https://forum.codewithmosh.com/t/object-equality/17518/3 "2023-01-08T03:46:35Z")

</div>

@SAM @YuriAmancio

LOL

My previous answer was so out of context.

To answer your question, I am not sure if using equality operator is a good technique to compare two memory address.  
Since memory address is about the execution environment, I am not sure if the language itself supports such feature (getting memory address of the variable).

---

<div class="post-metadata">

**Author:** ![SAM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sam/32/167_2.png) [@SAM](https://forum.codewithmosh.com/u/SAM)\
**Post date:** [January 8, 2023, 10:08am UTC](https://forum.codewithmosh.com/t/object-equality/17518/4 "2023-01-08T10:08:56Z")

</div>

@maverick I’m sure you have good intentions but

> [@YuriAmancio](#):
>
> The exercise is […] to check if the two objects are **referecing the same address** in memory.

---

<div class="post-metadata">

**Author:** ![YuriAmancio](https://avatars.discourse-cdn.com/v4/letter/y/e47c2d/32.png) [@YuriAmancio](https://forum.codewithmosh.com/u/YuriAmancio)\
**Post date:** [January 8, 2023, 11:32am UTC](https://forum.codewithmosh.com/t/object-equality/17518/5 "2023-01-08T11:32:57Z")

</div>

The exercise has another function to compare if the properties in these two objects are the same but in this case I wanted to clarify the same address in memory. Thanks for the tips.
