DEV Community

Abdulhafeez Abdulraheem
Abdulhafeez Abdulraheem

Posted on

What is the difference between dot notation and this : [''] while using an object in javascript

Apparently for some weird reasons I have been getting a bug on a web app and replacing it from dot notation to [''] solved it.

Observe:

from:

item.price = quantity * normal_price;

to:

item['price'] = quantity * normal_price;

Top comments (2)

Collapse
 
seanmclem profile image
Seanmclem •

The later allows you to use variables to reference object keys. That's one way

Collapse
 
feezyhendrix profile image
Abdulhafeez Abdulraheem •

This seems plausible