# Testing Objects and Properties

**URL:** <https://forum.freecodecamp.org/t/testing-objects-and-properties/459044>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [May 6, 2021, 1:44am UTC](https://forum.freecodecamp.org/t/testing-objects-and-properties/459044 "2021-05-06T01:44:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![erinfleming](https://avatars.discourse-cdn.com/v4/letter/e/71c47a/32.png) [@erinfleming](https://forum.freecodecamp.org/u/erinfleming)\
**Post date:** [May 6, 2021, 1:44am UTC](https://forum.freecodecamp.org/t/testing-objects-and-properties/459044/1 "2021-05-06T01:44:10Z")

</div>

```auto
function checkObj(obj, checkProp) {
  
  if(obj.hasOwnProperty(checkProp)){
    return obj[checkProp]
  }else{
    return "Not Found"
  }
  
}

```

Above is the code that works for the problem “Testing Objects and Properties”. It only works if you use “return obj[checkProp]”. It doesn’t work if you use “return obj.checkProp”. Why? Why doesn’t dot notation work in this situation?

---

<div class="post-metadata">

**Author:** ![DanCouper](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/dancouper/32/158608_2.png) [@DanCouper](https://forum.freecodecamp.org/u/DanCouper)\
**Post date:** [May 6, 2021, 3:35am UTC](https://forum.freecodecamp.org/t/testing-objects-and-properties/459044/2 "2021-05-06T03:35:13Z")

</div>

There is no key called `checkProp` on that object.

```auto
var obj = {
  example: 1
}

```

`obj.example` is `1`.  
`obj.checkProp` doesn’t exist.

```auto
var checkProp = "example";

var obj = {
  example: 1
}

```

`obj.example` is `1`.  
`obj.checkProp` doesn’t exist

`obj[checkProp]` is `1`.

The square brackets here say "evaluate what the value of the variable is inside them.  
The value is the string “example”

````auto
obj["example"]
,```

````

Which is now same as:

`obj.example`

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [May 6, 2021, 5:46am UTC](https://forum.freecodecamp.org/t/testing-objects-and-properties/459044/3 "2021-05-06T05:46:38Z")

</div>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (’).

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [November 4, 2021, 5:47pm UTC](https://forum.freecodecamp.org/t/testing-objects-and-properties/459044/4 "2021-11-04T17:47:20Z")

</div>

Closed on November 4, 2021, 5:47pm UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
