Carl Rippon

Building SPAs

Carl Rippon
BlogBooks / CoursesAbout
This site uses cookies. Click here to find out more

JavaScript Multi-line Strings

December 09, 2015
javascript

Traditionally I’ve always used something like the following when writing multi-line strings …

var build = "";
build += "<div>";
build += "	<label for='name'>name</label>";
build += "	<input type='text' id='name' />";
build += "</div>";

In ES6 you can write multi-line strings much cleaner using backticks rather than single or double quotes …

var build = `
<div>;
	<label for='name'>name</label>;
	<input type='text' id='name' />;
</div>`;

… which is much cleaner!

A backtick is a diagonal single quote which is at the top left of my keyboard.

The latest versions of Chrome, Firefox, Edge and Safari all support this. Unfortunately IE doesn’t.

Want more content like this?

Subscribe to receive notifications on new blog posts and courses

Required
© Carl Rippon
Privacy Policy