user-img
Language/JS 31
thumbnail
For ๋ฐ˜๋ณต๋ฌธ, For of, For in
1. For ๋ฐ˜๋ณต๋ฌธ // ์„ ์–ธ๋ถ€ ; ์กฐ๊ฑด๋ถ€; ์ฆ๊ฐ์—ฐ์‚ฐ๋ถ€; // ์กฐ๊ฑด์— ๋งž๋Š”์ง€ ํ™•์ธ -> loop ๋Œ๋ฆด๋ ค๋Š” ๋ช…๋ น ์‹คํ–‰ -> ์ฆ๊ฐ ์—ฐ์‚ฐ -> ์กฐ๊ฑด์— ๋งž๋Š”์ง€ ํ™•์ธ (๋ฐ˜๋ณต) for (let i = 0; i < 10; i++) { console.log(i); } (1) break loop๋ฅผ ๋Œ๋‹ค๊ฐ€ break๋ฅผ ๋งŒ๋‚˜๋ฉด ๊ทธ ์ž๋ฆฌ์—์„œ ํƒˆ์ถœ i๊ฐ€ 9๊ฐ€ ๋˜๋Š” ์ˆœ๊ฐ„ ํƒˆ์ถœ. (2) Continue continue๋ฅผ ๋งŒ๋‚˜๋ฉด, ํ•ด๋‹น ํ‚ค์›Œ๋“œ ๋ฐ‘์˜ ์ฝ”๋“œ๋“ค์€ ์‹คํ–‰ํ•˜์ง€ ์•Š๊ณ  ๋‹ค์‹œ loop๋กœ ๋Œ์•„๊ฐ. if ์กฐ๊ฑด ๋งŒ์กฑํ•ด์„œ continue ๋งŒ๋‚˜๋ฉด ๋ฐ‘์˜ ๋ฌธ์žฅ๋“ค ์‹คํ–‰ํ•˜์ง€ ์•Š๊ณ , ๋ฐ”๋กœ loop๋ฌธ์œผ๋กœ ๋„˜์–ด๊ฐ. if ์กฐ๊ฑด ๋งŒ์กฑ ๋ชปํ•ด์„œ ์ง€๋‚˜๊ฐˆ ๊ฒฝ์šฐ , ๊ทธ๋Œ€๋กœ console.log ์ฐํž˜. 2. For of ๋ฐ˜๋ณต๋ฌธ (๋ฐฐ์—ด์—์„œ ์“ฐ์ž„) java์—์„œ์˜ for ..
2023.04.14
Language/JS
thumbnail
If์™€ Switch ๋ฌธ
1. if 2. switch ๋ฌธ (1) ํ˜•ํƒœ let comment = ""; age = 14; switch (age) { case 14: comment = "์ค‘ํ•™๊ต 1ํ•™๋…„"; break; case 15: comment = "์ค‘ํ•™๊ต 2ํ•™๋…„"; break; case 16: comment = "์ค‘ํ•™๊ต 3ํ•™๋…„"; break; case 17: comment = "๊ณ ๋“ฑํ•™๊ต 1ํ•™๋…„"; break; case 18: comment = "๊ณ ๋“ฑํ•™๊ต 2ํ•™๋…„"; break; case 17: comment = "๊ณ ๋“ฑํ•™๊ต 3ํ•™๋…„"; break; default: comment = "์„ฑ์ธ์ด๊ฑฐ๋‚˜ ์ดˆ๋“ฑํ•™์ƒ์ž…๋‹ˆ๋‹ค."; } console.log(comment); ์ธ์ˆ˜๋กœ ๋ฐ›์€ ๊ฐ’์„ case ์— ์ ํ˜€์žˆ๋Š” ๊ฐ’๋“ค๊ณผ ์ฐจ๋ก€๋Œ€๋กœ ๋น„๊ตํ•œ๋‹ค. ๊ทธ ์ค‘ ์ผ์น˜ํ•˜..
2023.04.14
Language/JS
thumbnail
์„ ํƒ์  ์ฒด์ด๋‹(Optional Chaining)
**์™„์ „ ์ž˜ ๋ณด๊ณ  ๋ฐฐ์šด ๊ณณ ** ์˜ต์…”๋„ ์ฒด์ด๋‹ '?.' (javascript.info) ์˜ต์…”๋„ ์ฒด์ด๋‹ '?.' ko.javascript.info 1. Optional Chaining ์ด ์ƒ๊ธด ์ด์œ  (1) ์ƒ๊ธด ์ด์œ  ๊ฐ์ฒด ์•ˆ์˜ ๋ฉค๋ฒ„์˜ ๊ฐ’์„ ์–ป๊ธฐ ์œ„ํ•ด ์  ํ‘œ๊ธฐ๋ฒ•์œผ๋กœ ์ ‘๊ทผํ–ˆ๋Š”๋ฐ, ๊ทธ ๋ฉค๋ฒ„๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ˆœ๊ฐ„์ด ์žˆ๋‹ค. ์ด ๊ฒฝ์šฐ ์›๋ž˜๋ผ๋ฉด ์—๋Ÿฌ๊ฐ€ ๋‚œ๋‹ค. const User {} console.log(user.adderess); // syntax error ์ด์™€ ๊ฐ™์ด ์šฐ๋ฆฌ๊ฐ€ ๊ฐ์ฒด ์•ˆ์˜ ํŠน์ • ๋ฉค๋ฒ„์— ์ ‘๊ทผํ•˜๋ ค๊ณ  ํ•˜์ง€๋งŒ, ๊ทธ ๋ฉค๋ฒ„๊ฐ€ ์žˆ๋Š”์ง€ ์—†๋Š”์ง€ ๋ชจ๋ฅด๋Š” ๊ฒฝ์šฐ์— Error๋ฅผ ํ”ผํ•˜๊ธฐ ์œ„ํ•ด OptionalChaing์ด ๋งŒ๋“ค์–ด์ง„ ๊ฒƒ์ด๋‹ค. (2) Optional Chaining ์—†์—ˆ์„ ๋• ์–ด๋–ป๊ฒŒ ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ–ˆ๋‚˜์š”? && ์ด ..
2023.04.14
Language/JS
thumbnail
๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น
1. ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น์ด๋ž€? ๋งŒ์•ฝ ์šฐ๋ฆฌ๊ฐ€ ๋ฐฐ์—ด์—์„œ ์›์†Œ๋ฅผ ์ผ์ผํžˆ ๋นผ์„œ ๋ณ€์ˆ˜์— ์ง‘์–ด ๋„ฃ๋Š”๋‹ค๋ฉด, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ณผ์ •์„ ๊ฑฐ์ณ์•ผ ํ•  ๊ฒƒ์ด๋‹ค. const arr = [1,2,3] const a = arr[0] const b = arr[1] const c = arr[2] JS์—์„œ๋Š” ์œ„ ๊ณผ์ •์„ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•œ ์ค„์˜ ์ฝ”๋“œ๋กœ ์ ์„ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค. ์ด๋ฅผ ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น์ด๋ผ๊ณ  ํ•œ๋‹ค. ๋ฐฐ์—ด์ด๋‚˜ ๊ฐ์ฒด์˜ ์›์†Œ๋“ค์„ ์ฐข์–ด์„œ ๋ณ€์ˆ˜ ํ•˜๋‚˜ ํ•˜๋‚˜์— ๋„ฃ์–ด์ฃผ๋Š” ๋ฐฉ์‹์„ ๋งํ•œ๋‹ค. 2. ๋ฐฐ์—ด์—์„œ์˜ ๊ตฌ์กฐ ๋ถ„ํ•ด (1) ๊ธฐ๋ณธํ˜• // ๋ฐฐ์—ด ์„ ์–ธ const arr = [1,2,3] // ๊ตฌ์กฐ ๋ถ„ํ•ด ํ• ๋‹น ์ด์šฉ: ๋ณ€์ˆ˜ a, b, c์— ๊ฐ๊ฐ 1, 2, 3์ด ์ฐจ๋ก€๋กœ ๋“ค์–ด๊ฐ„๋‹ค. const [a,b,c] = arr console.log(a,b,c) // 1 2 3์ด ..
2023.04.02
Language/JS
thumbnail
์ „๊ฐœ ์—ฐ์‚ฐ์ž
1. ์ •์˜ (1) ํ˜•ํƒœ const a = [1,2,3] console.log(a) // [1,2,3] console.log(...a) // 1,2,3 const b = {a:'apple', b: 'banana', c: 'car'} const c = {d:'digest', e: 'earth', f: 'fool\'s day'} const r = {...b,...c} console.log(r) // {a:'apple', b: 'banana', c: 'car', d:'digest', e: 'earth', f: 'fool\'s day'} (2) ์ •์˜ ๋ฐฐ์—ด์ด๋‚˜ ๊ฐ์ฒด์˜ ์›์†Œ๋“ค์„ ์ฐจ๋ก€๋Œ€๋กœ ์ „๊ฐœํ•˜๋Š” ์—ฐ์‚ฐ์ž์ด๋‹ค. ๋ฐฐ์—ด์˜ ๋Œ€๊ด„ํ˜ธ๋‚˜, ๊ฐ์ฒด์˜ ์ค‘๊ด„ํ˜ธ๋ฅผ ๋ฒ—๊ธด๋‹ค. ** console.log() ์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ data๋ฅผ ์ฐ๋Š” ๋ฒ• ,..
2023.04.02
Language/JS
thumbnail
Nullish ๋ณ‘ํ•ฉ ๊ณผ ์‚ผํ•ญ ์—ฐ์‚ฐ์ž
1. Nullish๋ณ‘ํ•ฉ (1) ์ •์˜ const num = A ?? B ?? C ... // null ์ด๋‚˜ undefined๊ฐ€ ์•„๋‹Œ ๋งจ ์ฒ˜์Œ ๋งŒ๋‚œ data๋ฅผ ๋ฐ˜ํ™˜ // ๋งŒ์•ฝ ์—ฐ์‚ฐ์ž ์•ˆ์— ๋ชจ๋“  ๊ฐ’๋“ค์ด null ์ด๋‚˜ undefined ๋ผ๋ฉด ๋งจ ๋งˆ์ง€๋ง‰์˜ nullish ๊ฐ’์„ ๋ฐ˜ํ™˜ // (null , undifined ํ•ฉ์ณ์„œ nullish๋ผ๊ณ  ํ•œ๋‹ค.) OR์€ false๊ฐ€ ์•„๋‹Œ ๋งจ ์ฒ˜์Œ ๋งŒ๋‚œ data๋ฅผ ๋ฐ˜ํ™˜ ํ•˜๋Š” ์—ฐ์‚ฐ์ž์˜€๋‹ค. Nullish ๋ณ‘ํ•ฉ์€ OR ๋ณด๋‹ค ๊ฑฐ๋ฅด๋Š” ๋ฒ”์œ„๊ฐ€ ์ ์–ด์ง„ ์—ฐ์‚ฐ์ž์ด๋‹ค. (2) ์˜ˆ์‹œ๋“ค a. OR ๊ณผ Nullish์˜ ์ฐจ์ด 0์€ false ๊ฐ’์ด๊ณ , 7์ด ์ œ์ผ ๋จผ์ € ๋งŒ๋‚œ 0์ด ์•„๋‹Œ ๊ฐ’์ž„์œผ๋กœ 7์„ ๋ฐ˜ํ™˜ 0์€ ์ œ์ผ ์ฒ˜์Œ ๋งŒ๋‚œ nullish๊ฐ€ ์•„๋‹Œ ๊ฐ’์ž„์œผ๋กœ 0์„ ๋ฐ˜ํ™˜ b. ๋‹ค์–‘ํ•œ ์—ฐ์‚ฐ๋“ค 2. ์‚ผํ•ญ ์—ฐ์‚ฐ์ž (..
2023.04.02
Language/JS
thumbnail
๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž && ||
1. ๊ทธ๋ฆฌ๊ณ  && (1) ์ •์˜ A&&B ๋Š” A, B ๋‘˜ ๋‹ค ์ฐธ์ด์—ฌ์•ผ์ง€๋งŒ ์ฐธ์„ ๋ฐ˜ํ™˜ const A = true const B = true if (A&&B) { console.log('A,B ๋‘˜ ๋‹ค ์ฐธ์ด๋‹ค.') } // A,B ๋‘˜ ๋‹ค ์ฐธ์ด๋‹ค ๋ฐ˜ํ™˜ (2) JS๋งŒ์˜ ํŠน์ด์  ์œ„์—์„œ ๊ทธ๋ƒฅ 'A,B ๋‘˜ ๋‹ค ์ฐธ์ด๋ฉด ์ฐธ์„ ๋ฐ˜ํ™˜' ํ•œ๋‹ค๊ณ  ๋งํ–ˆ์ง€๋งŒ, JS๋Š” ๋‹ค๋ฅธ ์–ธ์–ด๋“ค๊ณผ ๋‹ฌ๋ฆฌ ์—ฌ๊ธฐ์„œ ๊ทธ์น˜์ง€ ์•Š๊ณ  ์ž๊ธฐ๋“ค๋งŒ์˜ ๊ทœ์น™์ด ์žˆ๋‹ค. ๋งŒ์•ฝ์— A&&B ์ž์ฒด๋ฅผ console์— ์ฐ๋Š”๋‹ค๊ณ  ํ•˜์ž. ๋‹ค๋ฅธ ์–ธ์–ด ๊ฐ™์•˜์œผ๋ฉด, A = 0 , B = 1 ์ด๋ฉด false๋ฅผ ์ฐ๋Š”๋‹ค. (0์€ ๊ฑฐ์ง“, 0์ด ์•„๋‹Œ ์ˆซ์ž๋Š” ๋ชจ๋‘ ์ฐธ ์ทจ๊ธ‰์„ ํ•˜๋ฏ€๋กœ ) ํ•˜์ง€๋งŒ JS๋Š” 0์ด ์ถœ๋ ฅ๋œ๋‹ค. ์ด๋ ‡๊ฒŒ ๋˜๋Š” ์ด์œ ๋Š” JS ๋งŒ์˜ ๊ทœ์น™์ด ์กด์žฌํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. JS์—์„œ์˜ && ์—ฐ์‚ฐ์ž๋Š” ๊ฐ€์žฅ ๋จผ..
2023.04.02
Language/JS
๋ถ€์ •, ๋น„๊ต ์—ฐ์‚ฐ์ž
1. !์ด๊ฑฐ ๋ถ™์ด๋ฉด boolean ๊ฐ’์ด toggle์ด ๋จ. // ๋ถ€์ •(Negation) console.log(!true) console.log(!false) console.log(!0) console.log(!!0) // ์ค‘๋ณต toggle์ด ๊ฐ€๋Šฅ console.log(!!!0) console.log(!null) console.log(!undefined) console.log(!NaN) console.log(!'') console.log(!{}) console.log(![]) 2. ๋น„๊ต ์—ฐ์‚ฐ์ž //๋น„๊ต ์—ฐ์‚ฐ์ž const a = 1 const b = 3 // ๋™๋“ฑ ์—ฐ์‚ฐ์ž // (a,b ํ˜•์ด ๋‹ค๋ฅผ ๊ฒฝ์šฐ ์ž๋™์œผ๋กœ ํ˜• ๋ณ€ํ™˜ ํ•ด์„œ ๋น„๊ตํ•จ. ๋”ฐ๋ผ์„œ 0 ๊ณผ '0'๋„ ๊ฐ™๋‹ค๊ณ  ๋ฐ˜ํ™˜ํ•œ๋‹ค. ์ด๋Š” ๋ถ€์ •ํ™•์„ฑ์„ ์ดˆ๋ž˜ํ•˜์—ฌ ์•ˆ ์“ฐ๋Š” ..
2023.03.31
Language/JS