Advanced JSX 11/16. Why the straight brackets?


#1


https://www.codecademy.com/courses/react-101/lessons/react-jsx-advanced/exercises/jsx-conditionals-ternary?action=lesson_resume
Advanced JSX 11/16


This does not work

var img = <img src={pics.{coinToss() == 'heads' ? 'kitty' : 'doggy'}} />;

While this does.

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

I don't understand why this is. What's the significance of the [and ]?
I added the . in the first code because I thought the text that needed to be passed to the img src needed to be
pics.kitty
or
pics.doggy


#2

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