-
Notifications
You must be signed in to change notification settings - Fork 0
/
operator.js
87 lines (71 loc) · 1.88 KB
/
operator.js
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
// 1. String concatenation
console.log('my' + ' cat');
console.log('1' + 2);
console.log('string literals: 1 + 2 = ${1+2}');
// 2. Numeric operators
console.log(1 + 1);
console.log(1 - 1);
console.log(1 * 1);
console.log(1 / 1);
console.log(1 * 1);
console.log(5 % 2);
console.log(2 ** 3);
//3. Increment and decrement operators
let counter = 2;
console.log('preIncrement: ${preIncrement}, counter: %{counter}');
const postIncrement = counter++
//4. Assignment operators
let x = 3;
let y = 6;
x += y; // x = x+y;
x -= y;
x *= y;
x /= y;
// 5. Comparison operators
console.log(10 < 6);
//등등 이런식으로 비교하는 거.
// 6. Logical operators, || or, && and.! not
// not 은 진리값을 반대로 바꿔준다.
// 7. Equality
const stringFive = '5';
const numerFive = 5;
// == loose equality, with type conversion
console.log(stringFive == numerFive);
console.log(stringFive != numerFive);
// === strict equality, no type conversion
console.log(stringFive === numerFive);
console.log(stringFive !== numerFive);
// 0, '', null -> 전부 False 값으로 간주될 수 있음.
// == 으로 False 와 비교하면 괜찮지만 ===으로 하면 아니다.
// 8. Conditional operators: If
// if, else if, else
const name = 'likelion';
if(name === 'likelion') {
console.log('Welome,likelion!');
} else if (name === 'coder') {
console.log('You are amazing coder');
} else {
console.log('unknown');
}
// 9. Ternary operator: ?
// condition ? value 1 : value 2;
console.log (name === 'likelion' ? 'yes' : 'no')
//10. Switch statement
// use for multiple if checks
//11. Loops
let i = 3;
while (i>0) {
console.log(`while: ${i}`);
i--;
}
//do while loop
do {
console.log(`do while: ${i}`);
i--;
} while (i > 0);
//for loop, for(begin; condition; step)
for (i = 3; i > 0; i--){
console.log(`for: ${i}`);
}
// nested loops for문을 안에 여러 개 넣는 것.
// Break, continue