mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 15:18:01 +00:00
Add String Interpolation With Template Literals as a javascript til
This commit is contained in:
17
javascript/string-interpolation-with-template-literals.md
Normal file
17
javascript/string-interpolation-with-template-literals.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# String Interpolation With Template Literals
|
||||
|
||||
ES6 adds support for [template
|
||||
literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals).
|
||||
Template literals make it much easier to compose strings of content --
|
||||
string interpolation. They allow for single and double quotes without having
|
||||
to fuss with escaping. Embedded expressions are also supported which means
|
||||
you can avoid awkward-to-type string concatenation with the `+` operator.
|
||||
|
||||
Here is an example:
|
||||
|
||||
```javascript
|
||||
> let movie = 'it'
|
||||
undefined
|
||||
> `What's up, I just saw "${movie.toUpperCase()}".`
|
||||
"What's up, I just saw "IT"."
|
||||
```
|
||||
Reference in New Issue
Block a user