Template literals with nested backticks(`) in ES6

Solution 1:

From ES6 In Depth: Template strings by Jason Orendorff:

If you need to write a backtick inside a template string, you must escape it with a backslash: `\`` is the same as "`".

Your query should be:

var query = `UPDATE packet
  SET
  \`association\` = "3485435",
  \`tagname\` = "Simos"`

Solution 2:

See 11.8.6 Template Literal Lexical Components

A template without substitutions is defined as

NoSubstitutionTemplate ::
    ` TemplateCharactersopt`

where a template character is

TemplateCharacter ::
    $ [lookahead ≠ { ]
    \ EscapeSequence
    LineContinuation
    LineTerminatorSequence
    SourceCharacter but not one of ` or \ or $ or LineTerminator

Therefore, ` can't be a template character unless you escape it by preceding it with \.

Solution 3:

As mentioned in other answers, you can escape the backtick ` with a backslash, like \`.

var tripleBacktickExample = `
\`\`\`python
# This JavaScript string contains some example Markdown that
# uses triple-backticks to delimit a Python code block.
\`\`\`
`

However, if you need very many backticks in a row ````` inside the template literal, it could be more readable to put them within a normal string that is inside a placeholder, like ${'`````'} or ${"`````"}.

var tripleBacktickExample = `
${'```'}python
# This JavaScript string contains some example Markdown that
# uses triple-backticks to delimit a Python code block.
${'```'}
`

Solution 4:

If you want to use an apostrophe in a string made with apostrophes, you escape it with a backslash, like this:

'\''

Similarly, if you want to use a backtick in a template literal, you have to escape it with a backslash:

`\``

Solution 5:

Use \`, it seems to work for me in the latest Chrome.