Last Updated: October 07, 2020
·
524
· jonabrams

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.

1 Response
Add your response

var props = [
  'I like it.',
  'Nice tip Jon!'
].join('\n');
over 1 year ago ·