Javascript Multiline String

Nov 3, 2017

For ES6, you can use String / Template Literals.

TIPS: you can use Babel (or use babel-loader with Webpack) for cross-browser support.

var html = `  <div>    <span>Hello</span>  </div>`

String concatenation way.

var text = 'I am happy.' +           'I am ' +           'sleeping now';

Slash concatenation (ES5).

var text = 'I \am \Home.';

Join array concatenantion.

var text = ['I ','am ','home.'].join('');

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.