// I'm not sure, I have this bad feeling // Breaking the line here is not good for some browers. // It doesn't feel right. var html_str = '<header>' + '<h1>Array Merging instead of string concatination</h1>' + '<h2>Formatting using array.join</h2>'+ '<p class="intro-para">A nice way to organize multiline strings.</p>'+ '</header>'; // I'm guilty of var html_str = '<header>' + '<h1>Array Merging instead of string concatination</h1>' + '<h2>A nice way to format using array.join</h2>'+ '<p class="intro-para">A nice way to organize multiline strings.</p>'+ '</header>'; // Sometimes written in one line var html_str = '<header>' + '<h1>Array Merging instead of string concatination</h1>' + '<h2>A nice way to format using array.join</h2>'+ '<p class="intro-para">A nice way to organize multiline strings.</p>' + '</header>'; // Using variables var title_variable = 'Array Merging instead of string concatination'; var sub_title_variable = 'A nice way to format using array.join'; var intro_para_variable = 'A nice way to organize multiline strings.'; var html_str = '<header>' + '<h1> ' + title_variable + ' </h1>' + '<h2> ' + sub_title_variable + '</h2>'+ '<p class="intro-para">' + intro_para_variable + '</p>' + '</header>';
// Make an array and join them together as a string. var html = [ '<header class="hello">', '<h2>Array Merging instead of string concatination</h2>', '<h3>A fancy Subtitle</h3>', '<p class="intro-para">Lorem Ipsum</p>', '</header>' ].join(''); // With Variables // It's nice that the comas are used for separation // and the + can be soley used for appending things. var title_variable = 'Array Merging instead of string concatination'; var sub_title_variable = 'A nice way to format using array.join'; var intro_para_variable = 'A nice way to organize multiline strings.'; var html = [ '<header class="hello">', '<h2>' + title_variable + '</h2>', '<h3>' + title_variable + '</h3>', '<p class="intro-para">' + title_variable + '</p>', '</header>' ].join(''); // Performance gains in maintainablity outway any small gains using a string. // Browsers are very fast at managing arrays like this.