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

Hi all


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’

lets simplify the code a little bit:


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

1 Like

Now I see it. Thanks