๐Ÿ‘พ 22.04.17 Study Log.

๐Ÿ‘พ ์˜ค๋Š˜ ๋ฐฐ์šด ๊ฒƒ
1. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ๋ณ€์ˆ˜ ๋„ค์ด๋ฐ : ์นด๋ฉœ ํ‘œ๊ธฐ๋ฒ• ์‚ฌ์šฉ
2. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ฐ์ดํ„ฐ ํƒ€์ž… : String, Number, Null, Undefine, Boolean(true or faluse)
3. ๋ณ€์ˆ˜ ์„ ์–ธ ๋ฐฉ๋ฒ•์€ ์ด 3๊ฐ€์ง€ : var(์˜ค๋ž˜๋œ ๋ฐฉ๋ฒ•, ์‚ฌ์šฉ X), const(์ƒ์ˆ˜, ์—…๋ฐ์ดํŠธ ๋ถˆ๊ฐ€, ๋””ํดํŠธ๋กœ ๋งŽ์ด ์‚ฌ์šฉ), let (์—…๋ฐ์ดํŠธ ๋ฐ ์ˆ˜์ • ๊ฐ€๋Šฅ, ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ ์ ˆํ•˜๊ฒŒ ์‚ฌ์šฉ)
4. Arrays ๋ฐฐ์—ด
5. Object ๊ฐ์ฒด

1. ์นด๋ฉœ ํ‘œ๊ธฐ๋ฒ•

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ๋„์–ด์“ฐ๊ธฐ๊ฐ€ ๋“ค์–ด๊ฐ€๋Š” ๊ฒฝ์šฐ์—๋Š” ๋Œ€๋ฌธ์ž๋ฅผ ์„ž์–ด ๊ตฌ๋ถ„ํ•ด์ค€๋‹ค.
์ด๋Ÿฌํ•œ ๋ชจ์Šต์ด ๋‚™ํƒ€์˜ ๋“ฑ๊ณผ ๋น„์Šทํ•˜๋‹ค ํ•ด์„œ ์นด๋ฉœํ‘œ๊ธฐ๋ฒ•์ด๋ผ ๋ถ€๋ฅธ๋‹ค.
์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ๋Š” ๊ด€ํ–‰์ ์œผ๋กœ ์ฃผ๋กœ ์นด๋ฉœ ํ‘œ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•œ๋‹ค.

const player name = "์Šน์œค"; โŒ
const playerName = "์Šน์œค"; ๐Ÿ‘

2. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ฐ์ดํ„ฐ ํƒ€์ž… 5๊ฐ€์ง€

(1) ๋ฌธ์ž์—ด(String)
๋ฌธ์ž๊ทธ๋Œ€๋กœ "๋ฌธ์ž" ์ฆ‰ ํ…์ŠคํŠธ๋ฅผ ๋œปํ•ฉ๋‹ˆ๋‹ค. " " or ' '๋กœ ์ž‘์„ฑํ•˜๋ฉด string ํƒ€์ž…์œผ๋กœ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

const name = "์Šน์œค";
console.log(name);
-> ์Šน์œค์ด๋ผ๊ณ  ์ฝ˜์†”์— ์ถœ๋ ฅ ๋จ
const numA = "2";
const numB = "3";
console.log(numA + numB);
-> 23์œผ๋กœ ์ถœ๋ ฅ๋จ / ๋ฌธ์ž์—ด๋กœ ์“ฐ์ธ ํ…์ŠคํŠธ๋Š” ์ˆซ์ž๋กœ์„œ ํ•ด์„์ด ์•ˆ๋จ

(2) ์ˆซ์ž(Number)
์ด ๋˜ํ•œ ๋ง๊ทธ๋Œ€๋กœ ์ˆซ์ž๋กœ์„œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ ์ž‘๋™ํ•จ.

const numA = 2;
const numB = 3;
console.log(numA + numB);
-> 5๋ผ๋Š” ๊ฒฐ๊ณผ๋กœ ์ถœ๋ ฅ๋จ. 

(3) ๋ถˆ๋ฆฌ์–ธ(Boolean)

(4) Null
์ด๊ฒƒ๋„ ๋ง๊ทธ๋Œ€๋กœ ์•„๋ฌด๊ฒƒ๋„ ์—†์Œ์„ ๋œปํ•จ
๐Ÿ’ก Undefine๊ณผ์˜ ์ฐจ์ด์ ์€ ๊ฐ’์ด ์—†๋‹ค๋Š” ๊ฒƒ์„ ์ธ์œ„์ ์œผ๋กœ(์˜๋„์ ์œผ๋กœ) ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉ๋œ๋‹ค๋Š” ๊ฒƒ์ž„

(5) Undefine
๊ฐ’์ด ๋ถ€์—ฌ๋˜์ง€ ์•Š์Œ / ์ •์˜๋˜์ง€ ์•Š์Œ์„ ๋‚˜ํƒ€๋‚ด๋Š” ํƒ€์ž…

3. ๋ณ€์ˆ˜ ์„ ์–ธ var, const, let

(1) var
์˜ค๋ž˜๋œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ์˜ ๋ฐฉ์‹, ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ๋˜๋„๋ก ์ž์ œ, ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ๋ณดํ˜ธ๊ฐ€ ์‰ฝ์ง€ ์•Š์•„์„œ ์ง€์–‘ํ•ด์•ผ ๋จ
(2) const(์ƒ์ˆ˜)
const๋กœ ์„ ์–ธ๋œ ๋ฐ์ดํ„ฐ๋Š” ์ˆ˜์ •์ด ๋ถˆ๊ฐ€๋Šฅ ํ•จ. ๋””ํดํŠธ๋กœ ๋งŽ์ด ์‚ฌ์šฉ ๋จ
(3) let
์—…๋ฐ์ดํŠธ ๋ฐ ์ˆ˜์ •์ด ๊ฐ€๋Šฅํ•จ, ํ•„์š”์— ์˜ํ•ด์„œ ์ ์ ˆํ•˜๊ฒŒ ์‚ฌ์šฉ

4. Array ๋ฐฐ์—ด

๋ฐ์ดํ„ฐ๋ฅผ ์ •๋ฆฌํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜
์‚ฌ์šฉ ๋ฐฉ๋ฒ•
(1) ๋Œ€๊ด„ํ˜ธ([]) ์•ˆ์— ๋„ฃ์–ด์ฃผ๊ธฐ
(2) ์—ฌ๋Ÿฌ ๊ฐœ๋ฅผ ๋‚˜์—ด ํ•  ๋•Œ ,(์ฝค๋งˆ)๋กœ ๊ตฌ๋ถ„ํ•ด์ฃผ๊ธฐ
(3) ์•ˆ์— ๋„ฃ์„ ์ˆ˜ ์žˆ๋Š” ๊ฑด ์–ด๋– ํ•œ ๋ฐ์ดํ„ฐ ํƒ€์ž…์ด๋ผ๋„ ๊ฐ€๋Šฅํ•จ
(4) push ํŽ‘์…˜์„ ์ด์šฉํ•ด์„œ ์ถ”๊ฐ€ ์—…๋ฐ์ดํŠธ ๊ฐ€๋Šฅ
(5) ๋ฐฐ์—ด์—์„œ 1๋ฒˆ์€ 0๋ถ€ํ„ฐ ์‹œ์ž‘

const dayOfWeek = ["์›”", "ํ™”", "์ˆ˜", "๋ชฉ", "๊ธˆ", "ํ† "];
console.log(dayOfWeek[5]);
dayOfWeek.push("์ผ");
console.log(dayOfWeek[6]);

5. Object ๊ฐ์ฒด

์˜ค๋ธŒ์ ํŠธ๋Š” ์–ด๋ ˆ์ด์™€ ๋‹ค๋ฅด๊ฒŒ ์˜๋ฏธ๋ฅผ ์ดํ•ดํ•˜๊ธฐ๊ฐ€ ์‰ฝ๊ณ  ๋‹จ์ˆœ ๋‚˜์—ด ๋ฐฉ์‹์ด ์•„๋‹ˆ๊ณ  ๊ฐ๊ฐ ํ”„๋กœํผํ‹ฐ์— ์ ํ•ฉํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ํ™œ์šฉ ๋ฐฉ๋ฒ•์— ์ฐจ์ด๊ฐ€ ์žˆ๋‹ค.
์˜ค๋ธŒ์ ํŠธ ๋‚ด๋ถ€๋ฅผ ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์—๋Š” const๋ฅผ ์„ ์–ธํ•ด ๊ฐ์ฒด๋ฅผ ์ž‘์„ฑํ•˜๋”๋ผ๋„ ์•„๋ฌด ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค.
์‚ฌ์šฉ๋ฐฉ๋ฒ•
(1) ์ค‘๊ด„ํ˜ธ ์‚ฌ์šฉ {}
(2) property(์†์„ฑ ์ž‘์„ฑ)
(3) ํ”„๋กœํผํ‹ฐ ๊ฐ’์€ : ๋กœ ๋ถ€์—ฌํ•œ๋‹ค.(= ์‚ฌ์šฉ์•ˆํ•จ)
(4) ํ”„๋กœํผํ‹ฐ ์ถ”๊ฐ€๋Š” ,(์ฝค๋งˆ)๋ฅผ ์‚ฌ์šฉ
object ์˜ค๋ธŒ์ ํŠธ 1.์ค‘๊ด„ํ˜ธ ์‚ฌ์šฉ({}) 2. property(์†์„ฑ ์ž‘์„ฑ) 3. ํ”„๋กœํผํ‹ฐ ๊ฐ’์€ >> : << ๋ถ€์—ฌํ•œ๋‹ค.
(5)ํ”„๋กœํผํ‹ฐ ์ถ”๊ฐ€๋Š” ,(์ฝค๋งˆ)๋ฅผ ์‚ฌ์šฉ
(6) ํ”„๋กœํผํ‹ฐ ๋ช…์€ ๊ฐ์ฒด๋ช….์†์„ฑ๋ช…(player.age) = ๊ฐ์ฒด๋ช…"์†์„ฑ๋ช…" ๋‘๊ฐ€์ง€ ๋ฐฉ๋ฒ•์œผ๋กœ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋”ฐ.

const player = {
    name : "cute",
    level : 12,
    fat : true,
};
console.log(player.level)

console.log(player);
console.log(player.name);

player.age = 27;
console.log(player);
console.log(player.age)
player.level = 21;
console.log(player.level)
console.log(player["level"])
player.age = player.age + 10;
console.log(player.age);

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ