Question
I’m not getting an error but it isn’t printing out the variable, instead it prints out My name is myName. My favorite city is myCity.
. What’s wrong?
Answer
So remember, you need to use ${VARIABLE_NAME}
, not just VARIABLE_NAME
in the string. JavaScript doesn’t know what’s a variable name in your string unless you add in the ${}
, at which point it replaces the ${}
with whatever the string value is of what’s inside the ${}
into the outer string.