DEV Community

Abdulhafeez Abdulraheem
Abdulhafeez Abdulraheem

Posted on

1 2

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay