Is there a way to change the quotes of a string from double or single quotes to backticks in JavaScript after it has already been defined? I need to be able to add variables into the string.
I attempted using replace(), but it seems like the variable is not re-evaluated by JavaScript after the replace method is executed.
I am wondering if it is possible to achieve this dynamically, or if variables can only be manually added to a string in JavaScript?
Below is the code I have tried:
const variable = 9;
let strWithVar = "${variable}".replace(/"+/g, "`");
console.log(strWithVar);
The current output is:
${abc}