We are already aware of template literal as shown below:
When we use template literal, any JavaScript expression is valid within the
curly braces {}
.
So, What are tagged template literals ?
The output of the above code snippet is:
The first argument of blackBox
function is an array of strings and second argument is the resolved value of the first expression we passed.
But we can have n
number of template interpolation, for example:
NOTE: Tagged templates works well with ES6 arrow function declaration.
The output of the above code snippet is:
Applications of tagged templates:
High-level implementation of styled-components:
For in-depth understanding of how tagged templates are used by styled-components please check the source code here source code