ECMA Script(ES) ๋ฌธ๋ฒ
JavaScript ํ์ค์ธ ECMAScript์์๋ ์ฃผ๊ธฐ์ ์ผ๋ก ๋ณด๋ค ํธ๋ฆฌํ ์ฝ๋ ์์ฑ์ ์ํ ์๋ก์ด ๋ฌธ๋ฒ์ ์ ๋ฐ์ดํธ ํ๊ณ ์๋ค.
์๋ก์ด ๋ฒ์ ๋ช ์ ES5, ES6~ ์ ๊ฐ์ ๋ฐฉ์์ผ๋ก ํ๊ธฐํ๊ธฐ๋ ํ๊ณ , ํด๋น ์ฐ๋๋ฅผ ๋ปํ๋ ES2015, ES2016์ผ๋ก ํ๊ธฐํ๊ธฐ๋ ํ๋ค.
ES6์ ES2015๊ฐ ๋์ผํ ๋ฒ์ ์ ๋ค๋ฅธ ํ๊ธฐ๋ฒ์ด๋ผ๊ณ ๋ณผ ์ ์๋ค.
ํ์ฌ๋ ES2023๊น์ง ๋์จ์ํ
์์ฃผ ์ฌ์ฉ๋๋ ES๋ฌธ๋ฒ
Spread Operator - ์ ๊ฐ ์ฐ์ฐ์(ES6, ES2015~)
์ฃผ๋ก ๊ฐ์ฒด์ ๋ฐฐ์ด์์ ์ฌ์ฉํ๋ค.
ex) ์๋ณธ ๋ฐฐ์ด์ ๊ธฐ๋ฐ์ผ๋ก ํ๋ ์๋ก์ด ๋ฐฐ์ด ์์ฑ ๋ฐ ๋ฐฐ์ด ๋ด ์์๋ค์ ํ์ด๋ด๊ณ ์ ํ ๋
1
2
|
const cookies = ['์ด์ฝ', '์ค๋ ์ง'];
const newCookies = ['๋ฐ๋๋ผ', ...cookies, 'ํฌ๋']; // ['๋ฐ๋๋ผ', '์ด์ฝ', '์ค๋ ์ง', 'ํฌ๋'];
|
cs |
Destructuring assignment - ๊ตฌ์กฐ ๋ถํด ํ ๋น(ES6~)
ํ์ด์ฌ์ Unpacking๊ณผ ๋น์ทํ ๋ฌธ๋ฒ
ํน์ ๊ฐ์ฒด(ex, ๋ฐฐ์ด, ๊ฐ์ฒด ๋ฑ)์ ๊ตฌ์กฐ(Structure)๋ฅผ ๋ถํดํ์ฌ ๋ ๋ฆฝ๋ ์์๋ค๋ก ๋ชจ์ ํ ๊ฐ๋ณ ๋ณ์๋ค์ ํ ๋นํ๋ค๋ ์๋ฏธ
de(๋ฐ์์ด) structuring : ๊ตฌ์กฐ๋ฅผ ๊นจ๋ค
๊ฐ์ฒด ๊ตฌ์กฐ ๋ถํด ํ ๋น:
- ๊ฐ์ฒด์ ์์ฑ์ ๋ณ์๋ก ์ถ์ถํ ๋ ์ฌ์ฉํฉ๋๋ค.
- ์์ฑ์ ์ด๋ฆ์ ๊ธฐ๋ฐ์ผ๋ก ๋ถํดํ๋ฉฐ, ์์๋ ์ค์ํ์ง ์์ต๋๋ค.
- ์ํ๋ ์์ฑ ์ด๋ฆ์ ์ค๊ดํธ {} ์์ ๋ช ์ํฉ๋๋ค.
- ๋ณ์ ์ด๋ฆ์ ๊ฐ์ฒด์ ์์ฑ ์ด๋ฆ๊ณผ ์ผ์นํด์ผ ํ์ง๋ง, :๋ฅผ ์ฌ์ฉํ์ฌ ๋ค๋ฅธ ์ด๋ฆ์ ํ ๋นํ ์๋ ์์ต๋๋ค.
์์:
1
2
|
javascriptCopy code
const person = { name: 'John', age: 30 };
const { name, age } = person; // 'name'๊ณผ 'age' ์์ฑ์ ์ถ์ถ console.log(name); // John console.log(age); // |
cs |
๋ฐฐ์ด ๊ตฌ์กฐ ๋ถํด ํ ๋น:
- ๋ฐฐ์ด์ ์์๋ฅผ ๋ณ์๋ก ์ถ์ถํ ๋ ์ฌ์ฉํฉ๋๋ค.
- ์์์ ์์์ ๋ฐ๋ผ ๋ถํดํ๋ฉฐ, ์ด๋ฆ์ ์ค์ํ์ง ์์ต๋๋ค.
- ์ํ๋ ์์์ ์์น๋ฅผ ๋๊ดํธ [] ์์ ์์๋๋ก ๋ช ์ํฉ๋๋ค.
- ๋ฐฐ์ด์ ์์๋๋ก ๋ณ์์ ํ ๋น๋ฉ๋๋ค.
์์:
1
2
|
javascriptCopy code
const numbers = [1, 2, 3];
const [first, second] = numbers; // ์ฒซ ๋ฒ์งธ์ ๋ ๋ฒ์งธ ์์๋ฅผ ์ถ์ถ console.log(first); // 1 console.log(second); // |
cs |
์์ฝ:
- ๊ฐ์ฒด ๊ตฌ์กฐ ๋ถํด: ์์ฑ ์ด๋ฆ์ ๊ธฐ๋ฐ์ผ๋ก ํ๋ฉฐ, ์์๋ ๋ฌด์๋ฉ๋๋ค.
- ๋ฐฐ์ด ๊ตฌ์กฐ ๋ถํด: ์์์ ์์๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ๋ฉฐ, ์ด๋ฆ์ ๋ฌด์๋ฉ๋๋ค.
์ด๋ฌํ ์ฐจ์ด์ ์ ๋ฐ์ดํฐ ๊ตฌ์กฐ์ ๋ฐ๋ผ ์ ์ ํ ๋ฐฉ์์ผ๋ก ๋ณ์์ ๊ฐ์ ํ ๋นํ ๋ ์ ์ฉํ๊ฒ ์ฌ์ฉ๋ฉ๋๋ค.
Optional chaining - ์ต์ ๋ ์ฒด์ด๋(ES11, ES2020 ~)
๊ฐ์ฒด์ ํ๋กํผํฐ์ ์ ๊ทผํ ๋ . ๋ฅผ ํ์ฉํ๋๋ฐ, ๋ง์ฝ ํ๋กํผํฐ๊ฐ null์ผ ๊ฒฝ์ฐ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
๋ฐ๋ผ์ ์๋ฌ ๋ฐฉ์ ๋์ ์ ๊ฐ์ด ํ ๋น๋์ง ์์๋ค๋ undefined๋ก ๋ฐํ์์ผ์ ์๋ฌ๋ฅผ ๋ฐฉ์งํ๊ณ ์ ํ ๋ ์ฌ์ฉํ๋ ์ฐ์ฐ์๋ผ๊ณ ํ ์ ์๋ค.
-> ์ฆ, ์ ๊ทผํ๊ณ ์ ํ๋ ์ด๋ค ๊ฐ์ด ์กด์ฌํ ์๋ ์๊ณ , ์กด์ฌํ์ง ์์ ์๋ ์์ ๋ ์ฌ์ฉ
1
2
3
4
5
6
7
8
9
|
const user = {
name: 'Alice',
cellphone: {
number: '010-5555-5555',
}
};
const homePhones = user?.homePhones;
console.log(homePhones);
|
cs |
'๊ฐ๋ฐ ์ง์, ์คํฌ๋ฆฝํธ > JavaScript, TS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
State (0) | 2023.12.19 |
---|---|
Props, Properties (1) | 2023.12.19 |
Promise- ํ์ ์ฒ๋ฆฌ์ ์ฒด์ด๋(Chaining) (0) | 2023.12.10 |
Promise ๊ฐ์ฒด์ ์ํ (0) | 2023.12.10 |
Promise (0) | 2023.12.10 |
๋๊ธ