user-img
Language 91
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
์‚ฐ์ˆ  ํ• ๋‹น ์ฆ๊ฐ ์—ฐ์‚ฐ์ž
1. ์‚ฐ์ˆ  + - x / %(๋‚˜๋จธ์ง€ ์—ฐ์‚ฐ์ž) 2. ํ• ๋‹น // var -> ์žฌ์„ ์–ธ ์žฌํ• ๋‹น ์ „๋ถ€ ๊ฐ€๋Šฅ // let -> ์žฌ์„ ์–ธ ๋ถˆ๊ฐ€ ์žฌํ• ๋‹น ๊ฐ€๋Šฅ let a = 3 a = 5 // ok let a = 3 let a = 2 //Error // const -> ์žฌ์„ ์–ธ ์žฌํ• ๋‹น ์ „๋ถ€ ๋ถˆ๊ฐ€๋Šฅ const a = 3 a =4 //Error 3. ์ฆ๊ฐ let a = 2 console.log(++a) console.log(a) // ํ•ด๋‹น ์ถœ๋ ฅ๋ฌธ ์‹คํ–‰ํ•˜๊ธฐ ์ „์— a ๊ฐ’์— 1์„ ๋”ํ•ด๋ผ (์ถœ๋ ฅ 3 3) console.log(a++) console.log(a) // ํ•ด๋‹น ์ถœ๋ ฅ๋ฌธ ์‹คํ–‰ ํ›„์— a์— 1 ๋”ํ•ด๋ผ (์ถœ๋ ฅ 2 3)
2023.03.31
Language/JS
Type ํ™•์ธ
//๋ฐ์ดํ„ฐ ํƒ€์ž… ํ™•์ธ // console.log(typeof a) // ๊ทผ๋ฐ ์ด๊ฑธ๋กœ๋Š” null, ๋ฐฐ์—ด[] ๊ฐ์ฒด{} ๋Š” ํ™•์ธํ•˜์ง€ ๋ชปํ•œ๋‹ค. // Js์—์„œ๋Š” ํ•จ์ˆ˜๋„ ํƒ€์ž…์œผ๋กœ ์นœ๋‹ค. console.log(typeof 'hello' === 'string') console.log(typeof 123 === 'number') console.log(typeof false === 'boolean') console.log(typeof undefined === 'undefined') console.log(typeof null ==='object') console.log(typeof[] === 'object') console.log(typeof{} === 'object') console.log(typeof function (..
2023.03.31
Language/JS