How I write multi-line strings in JavaScript
Forget having to do the usual:
var bigString = 'Line 1\n' +
'Line 2\n' +
...;
Instead, make an array and join with the newline character:
var bigString = [
'Line 1',
'Line 2',
...
].join('\n');
I find this makes writing, reading, and editing more than a couple lines a lot easier.
Written by Jon Abrams
Related protips
1 Response
var props = [
'I like it.',
'Nice tip Jon!'
].join('\n');
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Related Tags
#javascript
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#