# Bracket Notation vs Dot

**URL:** <https://forum.freecodecamp.org/t/bracket-notation-vs-dot/491491>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [January 7, 2022, 9:46am UTC](https://forum.freecodecamp.org/t/bracket-notation-vs-dot/491491 "2022-01-07T09:46:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ViyanMd](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/viyanmd/32/243038_2.png) [@ViyanMd](https://forum.freecodecamp.org/u/ViyanMd)\
**Post date:** [January 7, 2022, 9:46am UTC](https://forum.freecodecamp.org/t/bracket-notation-vs-dot/491491/1 "2022-01-07T09:46:47Z")

</div>

Could anyone explain why `usersObj.users.online === true` doesn’t work, but usersObj[users].online does, even though both options are in solution hints. What’s the deal here ?

```auto
function countOnline(usersObj) {
let count = 0;
// Only change code below this line
for(let user in usersObj) {
if(usersObj[user].online === true) {
  count++;
}
}
return count;
// Only change code above this line
}

```

**Challenge:** Iterate Through the Keys of an Object with a for…in Statement

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-data-structures/iterate-through-the-keys-of-an-object-with-a-for---in-statement)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![anon22924398](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@anon22924398](https://forum.freecodecamp.org/u/anon22924398)\
**Post date:** [January 7, 2022, 9:57am UTC](https://forum.freecodecamp.org/t/bracket-notation-vs-dot/491491/2 "2022-01-07T09:57:28Z")

</div>

```auto
const users = {OP:'ViyanMd', reply:'santimir'}
for (let user in users){
let val = users[user]; console.log(val)
}

for (let user in users){
let val = users.user; console.log(val)
}

```

Run in browser console or [here](https://jsfiddle.net/0w1Lt8pu/)

---

<div class="post-metadata">

**Author:** ![liyaquathhassan](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/liyaquathhassan/32/239722_2.png) [@liyaquathhassan](https://forum.freecodecamp.org/u/liyaquathhassan)\
**Post date:** [January 7, 2022, 10:07am UTC](https://forum.freecodecamp.org/t/bracket-notation-vs-dot/491491/3 "2022-01-07T10:07:14Z")

</div>

Square bracket notation allows access to properties containing special characters and the selection of properties using variables.  
Using dot notation you can access properties that do not contain special characters or variables.

This article might help you [Dot Notation vs. Bracket Notation](https://codeburst.io/javascript-quickie-dot-notation-vs-bracket-notation-333641c0f781)

---

<div class="post-metadata">

**Author:** ![ViyanMd](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/viyanmd/32/243038_2.png) [@ViyanMd](https://forum.freecodecamp.org/u/ViyanMd)\
**Post date:** [January 7, 2022, 11:27am UTC](https://forum.freecodecamp.org/t/bracket-notation-vs-dot/491491/5 "2022-01-07T11:27:28Z")

</div>

I’ve missed the fact that user was a variable. Now I see. Thanks!

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 7, 2022, 11:40am UTC](https://forum.freecodecamp.org/t/bracket-notation-vs-dot/491491/6 "2022-01-07T11:40:19Z")

</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:** [July 8, 2022, 11:41pm UTC](https://forum.freecodecamp.org/t/bracket-notation-vs-dot/491491/7 "2022-07-08T23:41:14Z")

</div>

Closed on July 8, 2022, 11:41pm UTC

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