Template Strings Without Variable Interpolation

841 Views Asked by At

Is it possible to have a template string in JavaScript that does not interpolate the variable values? I would like to have actual JS code blocks (which will be multi-line and contain escape sequences) like this example:

...

return String.raw`console.log(\`Here is my code:\n\n ${code}\`);`

that I can pass between functions in my Node.js app. I have no problem escaping backticks but I'd like to know if there's an easy way to stop interpolation of the variables so that I can have template strings nested inside of my template string.

I know that one option is to define code as let code = '${code}'; but I was wondering if there was a cleaner way to do it where interpolation was completely turned off in the same way that String.raw turns off interpretation of escape sequences.

0

There are 0 best solutions below