Skip to content

Instantly share code, notes, and snippets.

@flipflop
Last active September 27, 2015 08:27
Show Gist options
  • Save flipflop/1240520 to your computer and use it in GitHub Desktop.
Save flipflop/1240520 to your computer and use it in GitHub Desktop.
String Concatenation in JavaScript
// old concatenation (creates a new variable in memory for each +)
var stuckTogetherOld = "value1" + "value2" + "value3";
// Better:
// Front End Performance Tip for string concatenation or JS Templates
var stuckTogether = ["value1", "value2", "value3"].join("");
// Quicker to execute
var tmpl = ''.concat(
'<div>',
'<span>foo<span>',
'</div>'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment