-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvaroable.js
205 lines (167 loc) · 4.32 KB
/
varoable.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// 1.Use strict
'use strict'
// 2.Variable
let globalName='global name';
{
let name='ellie';
console.log(name);
name='hello';
console.log(name);
}
console.log(name);
console.log(globalName);
// var 선언하기도 전에 쓸수 있어서 위험하다
// var hoisting -- 어디에 선언에 상관없이 제 위로 끌어 올려주다
// block scope를 철저히 무시한다.
{
age=4;
var age;
}
console.log(age);
// 3.contants
// 한번 설정되면 값이 변하지 않는다
// 왠만하면 설정하고 값이 변하지않는걸로 사용한다
// 1.보완상의 이유
// 2.동시에 값 변경을 막아준다
// 3.실수를 줄여준다
// Mutable = let Immutable=const
const daysInWeek=7;
const maxNumber=5;
// 4.Variable types
// primitive타입 더이상 작은걸로 나누어 지지않는다
// single item: number , string , boolean , null , symbol
// object타입 한박스 단위로 나누어준다
// function , first-class function
const count=14;
const size=14.1;
console.log(`value : ${count},type:${typeof count}`);
console.log(`value : ${size},type:${typeof size}`);
// 무한대 숫자 Infinity
const infinity=1/0;
// -Infinity
const negativeInfinity=-1/0;
// 숫자가 아닌값을 출력할때는 NaN으로 출력
const nAn='not a number' / 2;
console.log(infinity);
console.log(negativeInfinity);
console.log(nAn);
// bigInt
const bigInt=123456789456123123456789789456123n;
console.log(`vale: ${bigInt} , type:${typeof bigInt}`);
// string
const char='c';
const brendan='brendan';
const greeting='hello' +brendan;
console.log(`value : ${greeting} , type : ${typeof greeting}`);
const helloBob=`hi ${brendan}!`;
console.log(`value : ${helloBob},type : ${typeof helloBob}`);
console.log(`value:` + helloBob + 'type:' + typeof helloBob);
// boolean
// fale: 0,null,undefined,NaN,''
// true: any other value
const canRead=true;
const test=3<1; //false
console.log(`value: ${canRead}, type: ${typeof canRead}`);
console.log(`value:${test}, type: ${typeof test}`);
// null
let nothing=null;
console.log(`value: ${nothing}, type:${typeof nothing}`);
// undefined
let x;
console.log(`value: ${x}, type: ${typeof x}`);
// symbol, create unique identifiers for object
const symbol1=Symbol('id');
const symbol2=Symbol('id');
console.log(symbol1===symbol2);
const gSymbol1=Symbol.for('id');
const gSymbol2=Symbol.for('id');
console.log(gSymbol1===gSymbol2);
console.log(`value ${symbol2.description}, type:${typeof symbol2}`)
// 5.Dynamic typing : dynamically typed language
let text='hello';
console.log(text.charAt(0)); //h
console.log(`value: ${text}, type: ${typeof text}`);
text=1;
console.log(`value: ${text}, type: ${typeof text}`);
text='7'+5;
console.log(`value: ${text}, type: ${typeof text}`);
text='8'/'2';
console.log(`value: ${text}, type: ${typeof text}`);
// console.log(text.charAt(0)); //타입스크립트가 나오게 된다.
// object
const ellie={name:'ellie' , age:20};
console.log(`value: ${ellie}`);
ellie.age=21;
// equality - puzzler
console.log(0==false);
console.log(0===false);
console.log(''==false);
console.log(''===false);
console.log(null==undefined);
console.log(null===undefined);
// 8.Conditional operators :if
// if, else if,else
const name='ellie';
if(name==='ellie'){
console.log('Welcome, Ellie!');
}else if(name==='coder'){
console.log('You are amazing coder');
}else{
console.log('unkwnon');
}
// 9.Ternary operator:
console.log(name==='ellie' ? 'yes': 'no');
// 10.Switch statement
const browser='IE';
switch (browser){
case 'IE':
console.log('go away!');
break;
case 'Chorm':
console.log('love you');
break;
case 'Firefox':
console.log('lobe you!');
break;
default:
console.log('same all!');
break;
}
// 11.Loops
let i=3;
while (i>0){
console.log(`while: ${i}`);
i--;
}
// do while
do{
console.log(`do while: ${i}`);
i--;
}while(i>0);
// for loop
for(i=3;i>0;i--){
console.log(`for: ${i}`);
}
for(let i=3;i>0;i=i-2){
console.log(`inline variable for: ${i}`);
}
// nested loop
for(let i=0;i<10;i++){
for(let j=0;j<10;j++){
console.log(`i: ${i}, j:${j}`);
}
}
// 1.
for(let i=0;i<11;i++){
if(i%2 !==0){
continue;
}
console.log(`q1.${i}`);
}
// 2.
for(let i=0;i<11;i++){
if(i>8){
break;
}
console.log(`q2.${i}`);
}