February 2018
Intermediate to advanced
298 pages
8h 22m
English
Template strings also bring something called "expressions" to JavaScript. Earlier, there was no other choice than merely concatenating strings together. For example, to embed expressions within normal strings, you would do something like this:
var a = 20;var b = 10;var c = "JavaScript";var str = "My age is " + (a + b) + " and I love " + c;console.log(str);
The output is as follows:
My age is 30 and I love JavaScript
However, now template strings make it much easier to embed expressions in strings. Template strings can contain expressions in them. The expressions are placed in placeholders indicated by a dollar sign and curly brackets, that is, ${expressions}. The resolved value of expressions in the placeholders and the text between ...
Read now
Unlock full access