I have the following code in Ruby. I want to convert this code into JavaScript. what's the equivalent code in JS?
text = <<"HERE"
This
Is
A
Multiline
String
HERE
I have the following code in Ruby. I want to convert this code into JavaScript. what's the equivalent code in JS?
text = <<"HERE"
This
Is
A
Multiline
String
HERE
You have to use the concatenation operator '+'.
By using
\n
your source code will look like -By using
<br>
your browser output will look like -Downvoters: This code is supplied for information only.
This has been tested in Fx 19 and Chrome 24 on Mac
DEMO
You can do this...
Also do note that, when extending string over multiple lines using forward backslash at end of each line, any extra characters (mostly spaces, tabs and comments added by mistake) after forward backslash will cause unexpected character error, which i took an hour to find out
There's this library that makes it beautiful:
https://github.com/sindresorhus/multiline
Before
After
Using script tags:
<script>...</script>
block containing your multiline text intohead
tag;get your multiline text as is... (watch out for text encoding: UTF-8, ASCII)