[Solved-6 Solutions] Creating multiline string in javascript - javascript tutorial
Problem:
How to create multiline string in javascript ?
Solution 1:
This is some multi-lined string using a comment inside a function returned as a string.
Solution 2:
ECMAScript 6 (ES6) introduces as template literals. They have many features, variable interpolation among others, they can be created multiline in string. It is delimited by backticks:
Solution 3:
Using ES6/Babel, to a create multi-line strings simply by using backticks:
Interpolating variables is the feature that comes with back-tick delimited strings:
Using transpiles down to concatenation:
Solution 4:
The pattern text = <<"HERE" This Is A Multiline String HERE
is not available in js. This pattern have some complex or long multiline strings that time we are using an array pattern:
The pattern anonymous already showed.
Use this code:
ES20xx is supports as spanning strings for multiple lines instead of using template strings:
Solution 5:
This code is based on the serialization. It is defined to be implementation-dependent. It does work in all browsers.
Use this code:
The method has been successfully tested in the following browsers like IE 4 – 10, Opera 9.50 - 12 (not in 9-), Safari 4 - 6 (not in 3-), Chrome 1 – 45, Firefox 17 - 21 (not in 16-), Rekonq 0.7.0 - 0.8.0. A comment starting with /*!
will be preserved.
Solution 6:
You can try this: