Skip to content

Commit 17445cc

Browse files
committed
Added JavaScript examples
1 parent 98d00b2 commit 17445cc

File tree

12 files changed

+82
-1
lines changed

12 files changed

+82
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
*.log
3+
.DS_Store

.jshintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"esversion": 6,
3+
"node": true
4+
}

JavaScript/1-for.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
for (let i = 0; i < 10; i++) {
4+
console.log(i);
5+
}

JavaScript/2-while.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
let a = 0;
4+
while (a < 10) {
5+
console.log(a++);
6+
}

JavaScript/3-do-while.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
let i = 0;
4+
do {
5+
console.log(i++);
6+
} while (i < 10);

JavaScript/4-for-in.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
let arr = [7, 10, 1, 5, 2];
4+
arr.field = 'Value';
5+
6+
for (let i in arr) {
7+
console.log(i);
8+
}

JavaScript/5-for-of.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
let arr = [7, 10, 1, 5, 2];
4+
arr.field = 'Value';
5+
6+
for (let i of arr) {
7+
console.log(i);
8+
}

JavaScript/6-break.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
label1: {
4+
console.log('Hello');
5+
if (true) break label1;
6+
console.log('World');
7+
}
8+
9+
label2: {
10+
console.log('There');
11+
}

JavaScript/7-continue.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
let i = 0;
4+
5+
label1: while (i < 10) {
6+
i++;
7+
console.log('Hello');
8+
if (i === 5) continue label1;
9+
console.log('World');
10+
}

JavaScript/8-forEach.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
let a = [7, 10, 1, 5, 2];
4+
5+
a.forEach(function(item, i, arr) {
6+
console.log(i, arr, item);
7+
});
8+
9+
console.log();
10+
11+
[7, 10, 1].forEach(console.log);
12+
13+
console.log();
14+
15+
[7, 10, 1].forEach(x => console.log(x));

0 commit comments

Comments
 (0)