1. ๋ณ์(Variable)
- ๋ณ๊ฒฝ๋ ์ ์๋ ๊ฐ
- Mutable data type
- let (added in ES6) ํค์๋๋ฅผ ์ฌ์ฉํ์ฌ ์ ์ธ
- block scope({ })๋ด: ์ง์ญ / block scope ์ธ: ๊ธ๋ก๋ฒ
- rw(read/write)
1-1. var
- ๋ ์ด์ ์ฌ์ฉํ์ง ๋ง ๊ฒ
- ๊ฐ์ ์ ์ธํ๊ธฐ๋ ์ ์ ์ฌ์ฉํ ์ ์๋ค.
- block scope๊ฐ ์๋ค.
1-2. hoisting
- ์ด๋์ ์ ์ธํ๋์ ๋ฐ๋ผ ์๊ด์์ด, ํญ์ ์ ์ธ์ ์ ์ผ ์๋ก ๋์ด์ฌ๋ ค์ฃผ๋ ๊ฒ
- move declaration from bottom to top
- var๋ก ์ ์ธํ ํํ์์ด๋ function ์ ์ธ๋ฌธ ๋ฑ์ ์คํ ๋จ๊ณ์์ ํด๋น scope์ ๋งจ ์๋ก ์ฎ๊ธฐ๋ ๊ฒ
- ๋ณ์๊ฐ ํจ์ ๋ด์์ ์ ์๋ ๊ฒฝ์ฐ: ์ ์ธ์ด ํจ์์ ์ต์์๋ก hoist
- ๋ณ์๊ฐ ํจ์ ๋ฐ๊นฅ์์ ์ ์๋ ๊ฒฝ์ฐ: ์ ์ธ์ด ์ ์ญ ์ปจํ ์คํธ์ ์ต์์๋ก hoist
- hoisting๋ ๋ณ์์ ๊ฒฝ์ฐ ์ ์ธ์ด ํ ๋น๊ณผ ๋์์ ์ผ์ด๋๋ ๊ฒ์ด ์๋๋ผ, ์ ์ธ๋ถ๋ง ์ ํจ ๋ฒ์์ ์ต์๋จ์ผ๋ก hoist๋์ด ๊ฐ์ฅ ๋จผ์ ํด์๋๋ค
- var๋ block scope๊ฐ ์๋, function scope์์ ์ ํจํ๋ค!
- ์์ธ: js ๋ณ์ ์์ฑ๊ณผ ์ด๊ธฐํ(์ ์ธ๊ณผ ํ ๋น)๊ฐ ๋ถ๋ฆฌ๋์ด ์งํ๋๊ธฐ ๋๋ฌธ
2. ์์(Constant)
- ํ ๋ฒ ํ ๋นํ๋ฉด, ๊ฐ์ด ์ ๋ ๋ฐ๋์ง ์๋ ๊ฒ
- pointer๊ฐ ์ ๊ฒจ์์ด์, ํ ๋น ํ ๊ฐ ๋ณ๊ฒฝ ๋ถ๊ฐ
- Immutable data type
- const ํค์๋๋ฅผ ์ฌ์ฉํ์ฌ ์ ์ธ
- r(read only)
3. Variable types
- primitive: ๋ ์ด์ ์์ ๋จ์๋ก ๋๋์ด์ง ์ ์์, single item
- number, string, boolean, null, undefined, symbol
- object: single item๋ค์ ์ฌ๋ฌ ๊ฐ ๋ฌถ์ด์ ํ ๋จ์(box)๋ก ๊ด๋ฆฌ
- function
3-1. Number
- js๋ ์ซ์์ ํฌ๊ธฐ์ ์๊ด์์ด, number type์ ์ด์ฉํด์ ์ซ์๋ฅผ ์ธ ์ ์๋ค.
let a = 12; let b = 1.2;
- ์์ ๊ฐ์ด number์ด๋ผ๋ data type์ ์ ์ธํ์ง ์์๋ ๋๋ค.
- js์์๋ type์ด dynamicํ๊ฒ ๊ฒฐ์ ๋๊ธฐ ๋๋ฌธ์ด๋ค.
- Special numeric values
- infinity: ์์๋ฅผ 0์ผ๋ก ๋๋ ๊ฒ
- negativeInfinity(-infinity): ์์๋ฅผ 0์ผ๋ก ๋๋ ๊ฒ
- NaN: ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ, string์ ์ซ์๋ก ๋๋ ๊ฒ
3-2. String
- js์์๋ ๋ฌธ์๋ ๋ฌธ์์ด์ด๋ ๋ชจ๋ string type์ผ๋ก ํ ๋น๋๋ค.
- template literals(string): `string ${value}`
-
const brendan = 'brendan'; const helloBob = `hi ${brendan}!`; //template literals(string) console.log(`value: ${helloBob}, type: ${typeof helloBob}`);
-
3-3. Boolean
- false: 0, null, undefined, NaN, ' '
- true: false ์ด์ธ์ ๋ชจ๋ ๊ฐ
3-4. null๊ณผ undefined
let nothing = null; // null
let x; // undefined
null์ null๋ก ๊ฐ์ด ํ ๋น๋ ์ํ์ด๊ณ , undefined๋ ์ ์ธ์ ๋์์ผ๋ ์๋ฌด๋ฐ ๊ฐ์ด ์ง์ ๋์ง ์์ ์ํ์ด๋ค.
3-5. Symbol
- map์ด๋ ๋ค๋ฅธ ์๋ฃ๊ตฌ์กฐ์์ ๊ณ ์ ํ ์๋ณ์๊ฐ ํ์ํ ๋
- ๋์๋ค๋ฐ์ ์ผ๋ก ์ผ์ด๋ ์ ์๋ ์ฝ๋์์ ์ฐ์ ์์๋ฅผ ์ฃผ๊ณ ์ถ์ ๊ฒฝ์ฐ ๊ณ ์ ํ ์๋ณ์๊ฐ ํ์ํ ๋
-
const symbol1 = Symbol('id'); const symbol2 = Symbol('id'); console.log(symbol1 === symbol2); // false const gSymbol1 = Symbol.for('id'); const gSymbol2 = Symbol.for('id'); console.log(gSymbol1 === gSymbol2); // true console.log(`value: ${symbol1.description}, type: ${typeof symbol1}`);
- Symbol์ ๋ฐ๋ก ์ถ๋ ฅ ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ฏ๋ก, .description์ ์ด์ฉํด์ string ๋ณํ ํ ์ถ๋ ฅํด์ผ ํ๋ค.
3-6. Object
- ๋ฌผ๊ฑด, ๋ฌผ์ฒด๋ค์ ๋ํํ ์ ์๋ box ํํ
-
const ellie = { name: 'ellie', age: 20 } // const -> ๋ค๋ฅธ object๋ก ๋ณ๊ฒฝ ๋ถ๊ฐ ellie.age = 21;
4. Dynamic typing
- js๋ ์ ์ธํ ๋ ์ด๋ค type์ธ์ง ์ ์ธํ์ง ์๊ณ , ํ๋ก๊ทธ๋จ์ด ๋์ํ ๋(runtime) ํ ๋น๋ ๊ฐ์ ๋ฐ๋ผ์ type์ด ๋ณ๊ฒฝ๋ ์ ์๋ค.
-
let text = 'hello'; console.log(`value: ${text}, type: ${typeof text}`); // string text = 1; console.log(`value: ${text}, type: ${typeof text}`); // number text = '7' + 5; console.log(`value: ${text}, type: ${typeof text}`); // string text = '8' / '2'; console.log(`value: ${text}, type: ${typeof text}`); // number
์ฐธ๊ณ :
- youtube ๋๋ฆผ์ฝ๋ฉ by ์๋ฆฌ
https://www.youtube.com/watch?v=OCCpGh4ujb8&list=PLv2d7VI9OotTVOL4QmPfvJWPJvkmv6h-2&index=3
- https://m.blog.naver.com/tcloe8/221549773024
'language > javascript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Object (0) | 2021.11.25 |
---|---|
ํด๋์ค์ ์ค๋ธ์ ํธ์ ์ฐจ์ด์ (0) | 2021.11.25 |
Function (0) | 2021.11.25 |
operator, if, for loop (0) | 2021.11.25 |
async์ defer (0) | 2021.11.25 |