Grammatical, style, and confusing example changes (#31490)
This commit is contained in:
@ -5,9 +5,9 @@ title: Template Literals
|
||||
## Template Literals
|
||||
|
||||
## Introduction:
|
||||
When we want to use variable to make a string, it becomes very painful as we have to use + sign to concatenate and keep track of quotes.
|
||||
When we want to use a variable to make a string, it becomes very painful as we have to use a + sign to concatenate and keep track of quotes.
|
||||
|
||||
Now with ES6,We can make string using backticks and using placeholders which are indicated with dollar sign and curly braces, like ${expression } .
|
||||
Now with ES6, we can make the string using backticks. Then, insert the variable like this, ${variable}.
|
||||
```javascript
|
||||
const name='John';
|
||||
const city='London';
|
||||
@ -60,7 +60,7 @@ const data = {name: 'John', city: 'London', birthyear: 1900};
|
||||
const markup = `<div>${data.name} lives in ${data.city}. ${data.birthyear ? `<div>He was born in the year ${data.birthyear}</div>`:''}</div>`;
|
||||
```
|
||||
|
||||
In the example above, if birthyear is defined, then div with contents "He was born in the year" is generated otherwise there would be no div created.
|
||||
In the example above, if birthyear is defined, then the div with contents "He was born in the year" is generated otherwise there would be no div created.
|
||||
|
||||
We can also call functions inside the template strings.
|
||||
|
||||
|
Reference in New Issue
Block a user