Skip to content

Instantly share code, notes, and snippets.

@FlameWolf
FlameWolf / How-to-display-JavaScript-template-strings-in-markdown.md
Last active May 8, 2018 08:54
How to display JavaScript template strings in markdown

One way is to use double backticks to wrap your code.

Example:

To display alert(`The sum is ${a + b}`);, type ``alert(`The sum is ${a + b}`);``.

But the double-tick approach will not work if you want to wrap an entire template string inside them, like this: ​`Sum: ${a + b}`​.

The trick here is to use triple backticks and a Zero-Width Space (ZWS) character. Example: ``[ZWS]`Sum: ${a + b}`[ZWS]``.