Object property and value syntax reference and examples

Hi, I just had a simple question. Is there a good resource for understanding the syntax of using dot and bracketed object properties and values? I am nearing the end of the javascript section and I am having trouble.

consider this object

const obj = {
name : 'rio',
age : 20
}

console.log(obj.name); //output rio 
console.log(obj['name']) ; //output rio

look i am getting same output for dot notation and for [ ] method basically this are method for accesing object properties and its totaly upto you how you want to access your object properties

ya ther are some places you can’t use dot notation but [ ] can be used
for example :

const secondObj = {
            'full name'(){
                 return 'rio sanap';
              }
}
console.log(secondObj.full name()); // this will give me an error
console.log(secondObj['full name']()); // this will give me rio sanap
        

so here i can not access my method using dot notation who have space in there name .
but i can access that method using [ ] method

When i find i have questions like this, i tend to go to the source. In this case, the Mozilla Developer Network (MDN) is the primary reference for nearly all things javascript.

Thnx repliers, I think MDN is probably the place to start. Also, thanks for the examples above.

1 Like

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