Dot Notation Vs. Bracket Notation

C++, C#, Java, PHP, ect...
Post Reply
Mardonis
Posts: 139
Joined: Wed Jun 29, 2011 7:54 pm

Dot Notation Vs. Bracket Notation

Post by Mardonis »

What are yall's opinions for these, pros and cons wise?
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Dot Notation Vs. Bracket Notation

Post by Jackolantern »

I am assuming you are talking about languages like Javascript that mix arrays and objects, where you can use either dot notation (like an object) or bracket notation (like an array) to access members?

If you are, then I pretty much go with what seems to be the standard: use brackets when the member's name is not or may not be a proper JS identifier (such as starting with a number or including spaces). Use dot-notation for other members. Use brackets if you are using it like an array or list.
The indelible lord of tl;dr
Post Reply

Return to “Coding”