Lesson 11: Syntax Explanation for src={pics.doggy} versus src=pics'doggy'?


Hi, quick syntax (or maybe background operation) question!

Not stuck in an exercise, just looking for an explanation.

Valid Code:  <img src={pics[coinToss()==='heads' ? 'kitty' : 'doggy']} />;

Valid Code:  <img src={pics.doggy} />;

Not Valid Code:  <img src={pics'doggy'} />;

(So, to me, it seems obvious that whatever happens in the square brackets transforms the ‘var’ to .var
This is not explained, and so was looking for an explanation. Thanks.)


Are you familiar with JS? I might hope so if you do reactJS course

we can access object by doing .propertyName or ['propertyName'], ['propertyName'] is known associative array notation, we always use square brackets when accessing array

explained here:


the confusing thing is that objects are the same as associative array:



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