Template strings

Template string is all about making your code clearer. Imagine the following scenario:

var url = 'http://path_to_domain' + 
'path_to_resource' +
'?param=' + parameter +
'=' + 'param2=' +
parameter2;

So, what's wrong with this? The answer is readability. It's hard to imagine what the resulting string will look like, but it is also very easy for you to edit the previous code by mistake, and suddenly, the result will not be what you want. Most languages use a format function for this and that is exactly what template strings is, a format function. It is used in the following way:

var url = `${baseUrl}/${path_to_resource}?param=
${parameter}&param2={parameter2}`;

This is a much more condensed expression and so it is much easier to read, so use it, always.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset