Issue with String interpolation

“My name is {myName}. My favorite city is {myCity}.”


let myName = "Martin";
let myCity = "New York";
console.log("My name is ${myName}. My favorite city is ${myCity}.")

Can someone tell me what I’m doing wrong here?

to use es6 string interpolation with ${variable} the string should be enclosed in back-ticks, not quotation marks, as you can see in the example:

let myPet = 'armadillo'
console.log(`I own a pet ${myPet}.`)
// Output: 'I own a pet armadillo.'

see? back-ticks are used to enclose the string


I tried with what I thought was a backpack ( ´ ) but it kept dissapearing… I found out that Norwegian keyboards dont actually have backpacks apparently… Thats fun…

Edit: Thanks though :slight_smile:

backpack? that is something differently internally

you can always try to set your keyboard layout to en-US or something, or just copy the bactick, here is one for you:


or google how you get it on a norwegian keyboard


Im unfortunately using a Mac atm, and its autocorrecting everything -_- I meant a backtick… But yeah, for now ill just copypaste it :slight_smile:

Mac is a bit tricky sometimes, because it inserts smart quotes which is not ideal for programming, you might need to disable that.

macs must have a backtick? Is this your keyboard layout:

uhm… your backtick seems to be left of the backspace key, in your case its not positioned left of the 1 which is common

given its at the top, it seems you need to press shift + that key


Ah, I just pressed it normally, so I guess I got a normal tick… Still wierd how it dissapeared though, but thanks :slight_smile:

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