I need something like heredoc in JavaScript. Do you have any ideas for this? I need cross-browser functionality.
I found this:
heredoc = \'\\
ES6 Template Strings has heredoc feature.
You can declare strings enclosed by back-tick (` `) and can be expanded through multiple lines.
var str = `This is my template string...
and is working across lines`;
You can also include expressions inside Template Strings. These are indicated by the Dollar sign and curly braces (${expression}
).
var js = "Java Script";
var des = `Template strings can now be used in ${js} with lot of additional features`;
console.log(des); //"Template strings can now be used in Java Script with lot of additional features"
There are in fact more features such as Tagged Temple Strings and Raw Strings in it. Please find the documentation at
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings