-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdraft00.js
More file actions
127 lines (109 loc) · 1.84 KB
/
Copy pathdraft00.js
File metadata and controls
127 lines (109 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
'use strict';
// comment
/* still
comment */
var x1 = 233;
console.log(x1);
if (2>1) {x1 = 322;}
typeof(233);
// number
233;
2.33;
2.33e3;
-233;
NaN;
Infinity;
0xe9; //233
(1 + 2) * 5 / 2; //7.5
2 / 0; //Infinity
0 / 0; // NaN
10 % 3; //1
10.5 % 3; //1.5
// string
'abc';
"abc";
'\'';
"\"";
"\n\t\n\r\\";
'\x41'; //ASCII 'A'
'\u0041'; //utf-8 'A'
`233
233
233`; //backquote
'hello, ' + 233;
var x1 = 233;
`hello, ${x1}`;
'233'.length;
'233'[0];
'abc'.toUpperCase().toLowerCase();
'abc'.indexOf('bc')
'abc'.substring(0, 3)
// bool
true;
false;
2>1;
2===2; //never use "==" although js supports
2<1;
true && false;
true || false;
!true;
!false;
if (true) { alert('if1') }
if (false) { alert('never run'); } else { alert('if2'); }
NaN === NaN; //false
isNaN(NaN);
Math.abs(1-0.999)<0.1;
Boolean(null);
Boolean(undefined);
Boolean(0);
Boolean('');
Boolean(false);
//special
null;
undefined;
//array
[233,2.33,NaN,Infinity,'233',true,false,null,undefined,[]]
new Array(2,3,3);
[2,3,3][1]; //indexing start with 0
var x1 = [2,3,3];
x1.length;
x1[6] = 233;
x1.length;
for (var y of x1) { console.log(y); }
x1.forEach(function (element, index, array) { console.log(element.toString() + '::' + index.toString());});
//dict
var x1 = {
name: '233',
age: 233
};
x1.name;
x1['name'];
x1.name = '322';
delete x1.age;
'name' in x1;
'toString' in x1;
x1.hasOwnProperty('name');
x1.hasOwnProperty('toString');
//for-loop, while-loop, do-while-loop
var x1 = 0;
var i;
for (i=1; i<=100; i++){
x1 = x1 + i;
}
//Map
var x1 = new Map([['Michael',95],['Bob',75],['Tracy',85]]);
// var x1 = new Map();
x1.get('Bob');
x1.set('Adam', 67);
x1.has('Adam');
x1.delete('Adam');
for (var y of x1){
console.log(y[0]);
console.log(y[1]);
}
//Set
var x1 = new Set([2,3,3]);
x1.add('2');
x1.delete('2');
for (var y of x1){ console.log(y); }
x1.forEach( function(y){ console.log(y);} );