Why cant we use dot notation here instead of square bracket notation

Tell us what’s happening:
Describe your issue in detail here.
[Why cant we use dot notation here instead of square bracket notation]
for example - usersObj.user.online gives error why though ?

  **Your code so far**

function countOnline(usersObj) {
// Only change code below this line
let onlineCounter = 0;
for (let user in usersObj){    
  if(usersObj[user].online === true){
return onlineCounter;
// Only change code above this line
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

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

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

You use dot notation when you literally know the name of the property.
You use bracket notation when the property you want to access is stored in a variable.

// here you look for a property "user":

// here you look for a property  "Alan" or "Jeff"  or "Sarah", 
// depending on what the variable "user" evaluates to

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