JavaScript - console.log('My name is ${myName}. Doesn't work

Hi guys, just started JavaScript and I’m doing practice project called Dog Years, do you know why {} (dollar sign and curly braces) in Javascript doesn't work? I type; console.log('My name is {myName}. And get a response like this; My name is ${myName}.
I am using Chrome, and Java Script enabled.

Thank you

Template literals (docs) only work when the string is enclosed in backticks/grave accent.

1 Like

Thank you but still doesn’t work!

I type the following; console.log(‘My name is {myName}. I am {myAgeInDogYears}years old dog years.’);
Response: My name is {myName}. I am {myAgeInDogYears}years old dog years.

you enclosed your strings in apostrophes, that won’t do if you want to use the es6 template literals feature.

1 Like

you need to use this instead of ’ ’ you can find it under the ESC key as shown on the attached image keyboard-symbols

like @stetim94 said, you need to use


instead of

Do you see the difference? The first is a backtick, in American layout keyboards you can find that symbol right about the tab key. The second symbol is a simple quote.

Thank you so much, yes this ` worked :slight_smile: