Skip to content

Commit 0d11325

Browse files
committed
add es6 for...of and template string examples
1 parent 6c9c057 commit 0d11325

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,19 @@ for(var i=0; i<list.length; i++){
8383
// 2 c
8484
```
8585

86-
We can do the same thing with the powerful `forEach` Array method:
86+
We can do the same thing with the new ES6 [`for...of`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of) loop:
87+
88+
```
89+
let list = ["a", "b", "c"];
90+
for(let item of list){
91+
console.log(item);
92+
}
93+
// a
94+
// b
95+
// c
96+
```
97+
98+
And we can do the same thing with the powerful `forEach` Array method:
8799
```
88100
var list = ["a", "b", "c"];
89101
list.forEach(function(value, i){
@@ -95,7 +107,7 @@ list.forEach(function(value, i){
95107
```
96108

97109

98-
## What is Concatenation?
110+
## What is Concatenation? (Hard!)
99111
When we combine strings together, it's known as "concatenation". Here's an example:
100112

101113
```
@@ -130,5 +142,21 @@ var dynamic_paragraph = (
130142
dynamic_paragraph //=> "<p>words words words!</p>"
131143
```
132144

145+
## What is a Template String? (Easy!)
146+
New to ES6 are template strings. Once you get the hang of it, these are a lot easier than the string concatenation method above.
147+
148+
```
149+
let foo = "bar";
150+
`${foo}`; //=> "bar"
151+
`${foo} ${foo}` //=> "bar bar"
152+
```
153+
154+
```
155+
let words = "words words words";
156+
let html_string = `<p>${words}!</p>`;
157+
158+
html_string //=> "<p>words words words!</p>"
159+
```
160+
133161
## Solution
134162
Please see the `solution` branch!

0 commit comments

Comments
 (0)