Skip to content

Commit 229a759

Browse files
committed
๐Ÿšฉ: null๊ณผ undefined ๋ฐฉ์‹๊ณผ ๋ฐฉ๋ฒ•
1 parent 9cce71a commit 229a759

File tree

1 file changed

+3
-34
lines changed

1 file changed

+3
-34
lines changed

โ€Žsrc/index.tsโ€Ž

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,4 @@
1-
//enum : ํŠน์ • ๊ฐ’, ๊ณตํ†ต๋˜๋Š” ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ์žˆ๊ณ  ์‹ถ์„ ๋•Œ enum์„ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.enum์€ key, value๋กœ ๋‘ ์Œ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๋Š” ํŠน์ง•์ด ์žˆ๋‹ค.
1+
// null, undefined
22

3-
enum Os {
4-
Window = 3,
5-
Ios = 10,
6-
Android
7-
}
8-
9-
console.log(Os['Ios']); //10
10-
console.log(Os[10]); //Ios
11-
12-
//enum์„ ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž์—ด๋กœ ์ง€์ •ํ–ˆ์„ ๊ฒฝ์šฐ ๋‹จ๋ฐฉํ–ฅ์œผ๋กœ๋งŒ ์ž‘์šฉํ•œ๋‹ค. ์ฆ‰, ํ‚ค(Key)๋Š” ํ•ญ์ƒ ๋ฌธ์ž์—ด๋กœ ์ •์˜ ํ•ด์•ผํ•œ๋‹ค. ๊ฐ’(Value)์„ ๋ฌธ์ž์—ด๋กœ ์ •์˜ํ•˜๋ฉด ํ‚ค์™€ ํ˜ผ๋™์ด ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๊ทธ๋ ‡๋‹ค๋Š” ๊ฑฐ์ง€?
13-
enum Os2 {
14-
Window = 'win',
15-
Ios = 'ios',
16-
Android = 'and'
17-
}
18-
19-
//๊ฐ„์ ‘ ์ ‘๊ทผ
20-
//key
21-
console.log(Os2['Window']);
22-
console.log(Os2['Ios']);
23-
//value
24-
// console.log(Os2['ios']); //-> error
25-
// console.log(Os2['win']); //-> error key๋Š” ํ•ญ์ƒ ๋ฌธ์ž์—ด๋กœ ์ง€์ •๋˜์–ด ์žˆ์–ด์„œ ๊ฐ’(value)๊ฐ€ ๋ฌธ์ž์—ด์ด๋ฉด ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
26-
27-
//๊ทธ๋ ‡๋‹ค๋ฉด ๋ฌธ์ž์—ด๋กœ ์ •์˜ ๋˜์–ด ์žˆ๋Š” ๊ฐ’(value)์— ์ ‘๊ทผ์„ ์–ด๋–ป๊ฒŒ ํ• ๊นŒ? ์•„๋ž˜์™€ ๊ฐ™์ด ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค.
28-
29-
//์ง์ ‘ ์ ‘๊ทผ
30-
console.log(Os2.Window);
31-
//๊ฐ’ ํ• ๋‹น์„ ํ†ตํ•œ ์ง์ ‘ ์ ‘๊ทผ ๋ฐฉ์‹
32-
let myOs: Os2;
33-
34-
myOs = Os2.Window
35-
console.log(myOs);
3+
let a: null = null;
4+
let b: undefined = undefined;

0 commit comments

Comments
ย (0)