๐ค Language/๐จ JavaScript
JS ์กฐ๊ฑด๋ฌธ, ๋ฐ๋ณต๋ฌธ
๐ JS ๋๋ค ํจ์ export default function random() { return Math.floor(Math.random() * 10) } import getType from './getType' import random from './getRandom' // main ํจ์ ์ฐ๊ฒฐ ๐ JS ์กฐ๊ฑด๋ฌธ if else // if else console.log('์กฐ๊ฑด๋ฌธ if else') const m = random() if (m < 3) { console.log(m, '< ๋๋ค์ซ์๋ 3๋ณด๋ค ์๋ค.') } else if (m === 4) { console.log(m, 'm์ 4์ด๋ค.') } else { console.log(m, 'm์ 5 ์ด์์ด๋ค.') } ๐ JS ์กฐ๊ฑด๋ฌธ switch // switc..
JS ์ฐ์ฐ์ ์ฐ์ /ํ ๋น/๋น๊ต/๋ ผ๋ฆฌ/and/or/๋ถ์ /์ผํญ
๐ JS ์ฐ์ ์ฐ์ฐ์ // ์ฐ์ ์ฐ์ฐ์(arithmetic operatior) console.log('์ฐ์ ์ฐ์ฐ์') console.log('1 + 2 = ', 1 + 2) // 1 + 2 = 3 console.log('4 - 8 = ', 4 - 8) // 4 - 8 = -4 console.log('2 * 5 = ', 2 * 5) // 2 * 5 = 10 console.log('4 / 8 = ', 4 / 8) // 4 / 8 = 0.5 console.log('7 % 5 = ', 7 % 5) // 7 % 5 = 2 ๐ JS ํ ๋น ์ฐ์ฐ์ // ํ ๋น ์ฐ์ฐ์ let a = 4 console.log(a += 1) // a = 5 console.log(a -= 2) // a = 3 console.log(a *= 2) ..
JS ํ๋ณํ
๐ JS ๋ฌธ๋ฒ ์์ // ์คํ๋ฌธ console.log('hello world!') // hello world console.log(123) // 123 console.log(typeof "hello world!") // string console.log(typeof 123) // number console.log(true) // true console.log(typeof null) // object console.log(typeof undefined) // undefined console.log(typeof {}) // object console.log(typeof []) // object ๐ JS ํ๋ณํ export default function getType(data) { return Object.p..
JS Object (๊ฐ์ฒด)
Object Object๋ property๋ฅผ ๊ฐ์ง ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํด์ฃผ๋ฉฐ, { } ๋ฅผ ์ฌ์ฉํ๋ค. const player = { name : imae, level : 100, korean : true, }; console.log(player); property๋ฅผ ๋ถ๋ฌ์ค๋ ๋ฐฉ๋ฒ์ 2๊ฐ์ง๊ฐ ์๋ค. console.log(player.name); // imae console.log(player["name"]); // imae ๋ํ property๋ฅผ ๋ฐ๊พธ๋ ๊ฒ์ ๊ฐ๋ฅํ์ง๋ง ์ ์ธ๋ object๋ฅผ ๋ฐ๊พธ๋ ๊ฒ์ ๋ถ๊ฐ๋ฅํ๋ค. const player = { name : imae, level : 100, korean : true, }; console.log(player); player.level = 101; console.log..
JS. const, let, var ์ฐจ์ด์
Variable(๋ณ์)๋ฅผ ์ ์ธํ๋ ๋ฐฉ๋ฒ const -> ์์์ด๋ฏ๋ก ๊ฐ์ ๋ณ๊ฒฝํ ์ ์๋ค. let -> ๋ณ์๊ฐ์ ๋ณ๊ฒฝํ ์ ์๋ค. var -> ๋ณ์๊ฐ์ ๋ณ๊ฒฝํ ์ ์์ง๋ง, ์ค์๋ก ๊ฐ์ ์ ๋ฐ์ดํธํด๋ ์์์ฐจ๋ฆด ์ ์๋ค. ์ฌ์ฉํ์ง ๋ง์. const์ let ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ const๋ฅผ ๊ธฐ๋ณธ์ ์ผ๋ก ์ฌ์ฉํ์. ์ ๋ฐ์ดํธ๊ฐ ํ์ํ ๋ณ์๋ผ๋ฉด let์ ์ฌ์ฉํ์. ํ์ ๋๋ถ๋ถ const๋ก ๋ณ์๋ฅผ ์ ์ธํ์.
JS. Camelcase
Camelcase ๋จ์ด๊ฐ ํฉ์ณ์ง ๋ถ๋ถ๋ง๋ค ๋งจ ์ฒ์ ๊ธ์๋ฅผ ๋๋ฌธ์๋ก ํ๊ธฐํ๋ ๋ฐฉ๋ฒ ๊ธธ์ด๊ฐ ๊ธด ๋ณ์๋ฅผ ์ ์ธํ ๋ → Camelcase ex. VeryLongVariableName cf. Python์์๋ very_long_variable_name
JS. JS ๋๊ตฌ
ํ๋ก์ ํธ์, ์ต์ํ์ ๋๊ตฌ๋ง์ผ๋ก ์์์ ๋ฐ๋ผ ์คํ๋์ด์ผ ํ ๋ช ๋ น๋ค์ด ์คํ๋์ด์ผ ์ต์ํ์ ์ง์์ผ๋ก ํ์ค์ ๋ฌธ์ ๋ฅผ ์ฐ๊ฒฐํ๋ค. ์นํ์ด์ง๊ฐ ์๋๋ผ ์น๋ธ๋ผ์ฐ์ ์์ฒด๋ฅผ ์ ์ดํด์ผ ํ๋ค๋ฉด ์๋์ฐ document ๊ฐ์ฒด ํ์ด์ง๋ด์ ํ๊ทธ ์กฐ์ DOM ๊ฐ์ฒด document ๊ฐ์ฒด๋ก๋ ์๋๋ ์์ ์ DOM๋ฌธ์๋ฅผ ํ์ธ window ๊ฐ์ฒด ์นํ์ด์ง๊ฐ ์๋ ์น ๋ธ๋ผ์ฐ์ ์์ฒด๋ฅผ ์ ์ดํด์ผ ํ๋ ๊ฒฝ์ฐ, ํ์ธ ex. ํ์ฌ ์ด๋ฆฐ ์นํ์ด์ง์ ์ฃผ์๊ฐ ํ์ํ ๊ฒฝ์ฐ, ์๋ก์ด ๋ธ๋ผ์ฐ์ ์ฐฝ์ ์ด์ด์ผ ํ ๋, ๋ธ๋ผ์ฐ์ ํ๋ฉด ํฌ๊ธฐ ์ ๋ณด๊ฐ ํ์ํ ๊ฒฝ์ฐ Ajax ์นํ์ด์ง๋ฅผ reloadํ์ง ์๊ณ , ์ ๋ณด๋ฅผ ๋ณ๊ฒฝํ๊ณ ์ถ๋ค๋ฉด Morden web page ๋ฅผ ์ํ ํ์ ๊ธฐ์ Cookie ์นํ์ด์ง๊ฐ reload๋์ด๋ status๋ฅผ ์ ์งํด์ผ ํ ๊ฒฝ์ฐ, ์ฌ์ฉ์๋ฅผ ์ํ ๊ฐ์ธํ๋ ..
JS. ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ํ๋ ์์ํฌ, UI vs API
โป ์ํ์ฝ๋ฉ ์ ์๋์ "๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ํ๋ ์์ํฌ" ๊ฐ์๋ฅผ ์๊ฐํ๊ณ ์์ฑํ ๊ธ์ ๋๋ค. library vs framework library: ๋ถํ์ ๊ฐ์ ธ์ค๋ ์ญํ - > jQuery ์ด์ฉ -> CDN (Content Delivery Network) framework: ์ผ์ข ์ ํ ํ๋ฆฟ ์ญํ UI vs API UI User's interface for using application ์ฌ๋(์ฌ์ฉ์)๊ณผ ์ฌ๋ฌผ ๋๋ ์์คํ , ํนํ ๊ธฐ๊ณ, ์ปดํจํฐ ํ๋ก๊ทธ๋จ ๋ฑ ์ฌ์ด์์ ์์ฌ์ํต์ ํ ์ ์๋๋ก ์ผ์์ ๋๋ ์๊ตฌ์ ์ธ ์ ๊ทผ์ ๋ชฉ์ ์ผ๋ก ๋ง๋ค์ด์ง ๋ฌผ๋ฆฌ์ , ๊ฐ์์ ๋งค๊ฐ์ฒด๋ฅผ ๋ปํ๋ค. API Programmer's Interface for programming ์ปดํจํฐ๋ ์ปดํจํฐ ํ๋ก๊ทธ๋จ ์ฌ์ด์ ์ฐ๊ฒฐ์ด๋ค. ์ผ์ข ์ ์ํํธ์จ์ด ์ธํฐํ์ด์ค์ด๋ฉฐ ๋ค..
JS. ํ์ผ๋ก ์ชผ๊ฐ์ js์ฝ๋ ๊ด๋ฆฌ
โป ์ํ์ฝ๋ฉ ์ ์๋์ "ํ์ผ๋ก ์ชผ๊ฐ์ ์ ๋ฆฌ ์ ๋ํ๊ธฐ" ๊ฐ์๋ฅผ ์๊ฐํ๊ณ ์์ฑํ ๊ธ์ ๋๋ค. js ์ฝ๋๋ง ๋ฐ๋ก ๊ด๋ฆฌํ๋ ๋ฒ js ์ฝ๋๋ง ๋ฐ๋ก ๊ด๋ฆฌํ ๋ ์ฅ์ ํ๋ก๊ทธ๋จ ์ ์ง๊ด๋ฆฌ๋ณด์์ ํธ๋ฆฌ ์๋ฒ ๋น์ฉ ์ ๊ฐ ํธ๋ํฝ ์ ๊ฐ ์บ์
JS. ๊ฐ์ฒด
โป ์ํ์ฝ๋ฉ ์ ์๋์ "๊ฐ์ฒด ํ์ฉ" ๊ฐ์๋ฅผ ์๊ฐํ๊ณ ์์ฑํ ๊ธ์ ๋๋ค. ๊ฐ์ฒด ํ๋กํผํฐ ๋ฉ์๋ ์ฉ์ด ์ ๋ฆฌ ๊ฐ์ฒด(Object) ์ด๋ฆ๊ณผ ๊ฐ์ผ๋ก ๊ตฌ์ฑ๋ ์ฑ์ง(property)์ ์ ๋ ฌ๋์ง ์์ ์งํฉ์ ๋๋ค. ํ๋กํผํฐ(property) ๊ฐ์ฒด์ ์์๋ ๋ณ์ ๋ฉ์๋(method) ๊ฐ์ฒด์ ์์๋ ํจ์ ์ ์ฝ๋์ ๊ฐ์ด ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ๊ธฐ ์ ์ ํจ์๋ก ์ค๋ณต์ ์ ๋ฆฌํด์ฃผ๋ ์์ ์ ํ๋ค. ๊ฐ์ฒด ์์ฑ ๋ฐฉ๋ฒ Create ์ด๋ฌํ ๊ฒฐ๊ณผ๋ก ๋ชจ๋ ๊ฐ์ฒด๊ฐ ์์ฑ๋๋ ๊ฒ์ ๋ณผ ์ ์๋ค. ๋ฐ๋ณต๋ฌธ Interate ๋ฐ๋ณต๋ฌธ์ ์ฌ์ฉํ๋ ๋ฒ for(var key in coworkers) key programmer, designer ๋ฑ coworkers[key] egoing, leezche ๋ฑ ๋ฉ์๋ ์์ฑ ๋ฐฉ๋ฒ ๋ฉ์๋๋? ๊ฐ์ฒด์ ์์๋ ํจ์ ๊ฐ์ฒด ํ์ฉ Body์ ..