Share on facebook
Facebook
Share on twitter
Twitter

ES6 for Now: Template Strings

ES6 is the future of JavaScript and it is already here. It is a finished specification, and it brings a lot of features a language requires to stay competitive with the needs of the web of now. Not everything in ES6 is for you and in this little series of posts I will show features that are very handy and already usable. If you look at JavaScript code I’ve written you will find that I always use single quotes to define strings instead of double quotes. JavaScript is OK with either, the following two examples do exactly the same thing: 1 2 var animal = “cow”; var animal = ‘cow’; The reason why I prefer single quotes is that, first of all, it makes it easier to assemble HTML strings with properly quoted attributes that way: 1 2 3 4 5 6 7 // with single quotes, there’s no need to // escape the quotes around the class value var but = ‘‘; // this is a syntax error: var but = ““; // this works: var but = ““; The only time you need to escape now is when you use a single quote in your HTML, which should be a […]

X