Learn ReactJS - The ternary operator 11/16 why the inverted commas?


#1

Hi all

https://www.codecademy.com/courses/react-101/lessons/react-jsx-advanced/exercises/jsx-conditionals-ternary?action=lesson_resume&link_content_target=interstitial_undefined

my code doesn’t behave incorrectly. My question is in code below, why are kitty and doggy in inverted commas, this does not seem to follow the logic as they are constant names not strings.



coinToss() == ‘heads’ ? ‘kitty’ : ‘doggy’



#2

lets simplify the code a little bit:

pics['kitty']

kitty is a string here, given we use it as key to get value from pics dictionary

the kitty and doggy are variables within the dictionary, yes, but these variable have a very limited scope (inside the dictionary), the key has to be a string, it can be a variable but then you get:

const kitty = 'kitty'

now we can use kitty variable as key to retrieve value from dictionary


#3

Now I see it. Thanks


#4