์ ์ฉํ 10๊ฐ์ง ๋ฐฐ์ด ํจ์๋ค
// Q1. make a string out of an array { const fruits = ['apple', 'banana', 'orange']; const result = fruits.join(' '); console.log(result); } // Q2. make an array out of a string { const fruits = '๐, ๐ฅ, ๐, ๐'; const result = fruits.split(', '); console.log(result); } // Q3. make this array look like this: [5, 4, 3, 2, 1] { const array = [1, 2, 3, 4, 5]; const result = array.reverse(); console.log..
๋ฐฐ์ด ๊ฐ๋ ๊ณผ APIs
Object - ์๋ก ์ฐ๊ด๋ ํน์ง๊ณผ ํ๋๋ค์ ๋ฌถ์ด๋๋ ๊ฒ ์๋ฃ๊ตฌ์กฐ - ๋น์ทํ type์ object๋ค์ ๋ฌถ์ด๋๋ ๊ฒ(dynamically typed language) - ๋ค๋ฅธ ์ธ์ด์ ๊ฒฝ์ฐ์๋ ๋์ผํ type์ object๋ง์ ๋ฌถ์ ์ ์๋ค. 1. Declaration const arr1 = new Array(); const arr2 = [1, 2]; 2. Index position const fruits = ['๐', '๐']; console.log(fruits); // ['๐', '๐'] console.log(fruits.length); // 2 console.log(fruits[0]); // ๐ console.log(fruits[1]); // ๐ console.log(fruits[2]); // und..
Object
1. Literals and properties const obj1 = {}; // 'object literal' syntax const obj2 = new Object(); // 'object constructor' syntax function print(person) { console.log(person.name); console.log(person.age); } const ellie = { name: 'ellie', age: 4 }; print(ellie); // js๋ object๋ฅผ ์ ์ํ ํ์๋ property ์ถ๊ฐ ๊ฐ๋ฅ ellie.hasJob = true; console.log(ellie.hasJob); // true // property ์ญ์ ๋ํ ๊ฐ๋ฅ delete ellie.hasJob; ..
ํด๋์ค์ ์ค๋ธ์ ํธ์ ์ฐจ์ด์
class - ์ฐ๊ด์๋ data๋ค์ ํ๊ณณ์ ๋ฌถ์ด๋๋ ์ปจํ ์ด๋ - ์์ฑ(fields), ํ๋(methods) - data class: ๊ด๋ จ์๋ data(field)๋ง ์ ์๋ ํด๋์ค - ์บก์ํ: ํด๋์ค ๋ด์์ ๋ด๋ถ์ ์ผ๋ก ๋ณด์ฌ์ง๋ ๋ณ์, ์ธ๋ถ์์ ๋ณด์ฌ์ง๋ ๋ณ์๋ฅผ ๋๋ - ์์๊ณผ ๋คํ์ฑ 1. Class ๋ถ์ด๋นต์ ๋ง๋ค ์ ์๋ ํ template(ํ)๋ง ์ ์, ์ค์ data๋ ๋ค์ด์์ง ์๋ค. ํ ๋ฒ๋ง ์ ์ธํ๋ค. 2. Object ํด๋์ค๋ฅผ ์ด์ฉํด์ ์ค์ data๋ฅผ ๋ฃ์ด์ ๋ง๋๋ ๊ฒ ํด๋์ค๋ฅผ ์ด์ฉํด์ ์์ฑ๋ ์๋ก์ด instance ์ฌ๋ฌ ๋ฒ ์์ฑ๋ ์ ์๋ค. 3. javascript์ class ES6์ ๋์ ๋์๋ค ๊ธฐ์กด์ prototype์ ๊ธฐ๋ฐ์ผ๋ก ๋ฌธ๋ฒ๋ง ์ถ๊ฐ๋์๋ค. (syntactical sugar) 4. Clas..
Function
1. Function - ์ฌ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค. - ํ ๊ฐ์ง์ task๋ฅผ ์ํํ๊ฑฐ๋ value๋ฅผ ๊ณ์ฐํ๊ธฐ ์ํด ์ฌ์ฉ๋๋ค. - object์ ์ผ์ข ์ด๋ค. 1-1. Function declaration function name(param1, param2) { body... return; } 2. Parameters premitive parameters: ๋ฉ๋ชจ๋ฆฌ์ value๊ฐ ๊ทธ๋๋ก ์ ์ฅ, value๊ฐ ์ ๋ฌ object parameters: ๋ฉ๋ชจ๋ฆฌ์ reference๊ฐ ์ ์ฅ, reference๊ฐ ์ ๋ฌ 3. Default parameters (added in ES6) function showMessage(message, from = 'unknown') { // from์ด undefined์ผ ๋, default ๊ฐ ๋ช ..
operator, if, for loop
1. String concatenation console.log('my' + 'cat'); // my cat console.log('1' + 2); // 12 console.log(`string literals: 1 + 2 = ${1 + 2}`); // string literals: 1 + 2 = 3 2. Numeric operators +, -, /, *, %, ** 3. Increment and decrement operators let counter = 2; const preIncrement = ++counter; // counter = counter + 1; // preIncrement = counter; const postIncrement = counter++; // postIncrement =..
data types, let vs var, hoisting
1. ๋ณ์(Variable) ๋ณ๊ฒฝ๋ ์ ์๋ ๊ฐ Mutable data type let (added in ES6) ํค์๋๋ฅผ ์ฌ์ฉํ์ฌ ์ ์ธ block scope({ })๋ด: ์ง์ญ / block scope ์ธ: ๊ธ๋ก๋ฒ rw(read/write) 1-1. var ๋ ์ด์ ์ฌ์ฉํ์ง ๋ง ๊ฒ ๊ฐ์ ์ ์ธํ๊ธฐ๋ ์ ์ ์ฌ์ฉํ ์ ์๋ค. block scope๊ฐ ์๋ค. 1-2. hoisting ์ด๋์ ์ ์ธํ๋์ ๋ฐ๋ผ ์๊ด์์ด, ํญ์ ์ ์ธ์ ์ ์ผ ์๋ก ๋์ด์ฌ๋ ค์ฃผ๋ ๊ฒ move declaration from bottom to top var๋ก ์ ์ธํ ํํ์์ด๋ function ์ ์ธ๋ฌธ ๋ฑ์ ์คํ ๋จ๊ณ์์ ํด๋น scope์ ๋งจ ์๋ก ์ฎ๊ธฐ๋ ๊ฒ ๋ณ์๊ฐ ํจ์ ๋ด์์ ์ ์๋ ๊ฒฝ์ฐ: ์ ์ธ์ด ํจ์์ ์ต์์๋ก hoist ๋ณ์๊ฐ ํจ์ ๋ฐ๊นฅ์์ ..
async์ defer
1) user๊ฐ html ํ์ผ์ ๋ค์ด๋ฐ์์ ๋ ๋ธ๋ผ์ฐ์ ๋ ํ์ค์ฉ ํด์ ํ DOM ์์๋ก ๋ณํ(parsing) 2) parsing ์ค 1) ๋ธ๋ผ์ฐ์ ๊ฐ ์ญ parsingํ, ํ์ด์ง์ ์ค๋น๊ฐ ์๋ฃ๋์์ ๋ ๋ฅผ ๋ง๋์ fetching, executing โ ์ฅ๋จ์ : user๊ฐ ๊ธฐ๋ณธ์ ์ธ html์ ์ปจํ ์ธ ๋ฅผ ๋นจ๋ฆฌ ํ์ธํ ์๋ ์์ง๋ง, ์ฌ์ดํธ๊ฐ js์ ์์กด์ ์ด๋ผ๋ฉด user๊ฐ ์๋ฏธ์๋ ์ปจํ ์ธ ๋ฅผ ๋ณด๊ธฐ ์ํ ์ ์์ ์ธ ํ์ด์ง๋ฅผ ํ์ธํ๊ธฐ ์ ๊น์ง๋ fetching, executing ํ๋ ์๊ฐ์ ๋ชจ๋ ๊ธฐ๋ค๋ ค์ผ ํ๋ค. 1) ๋ธ๋ผ์ฐ์ ๊ฐ html ๋ค์ด ํ parsing ํ๋ค๊ฐ, async๋ง๋์ ๋ณ๋ ฌ๋ก main.js ํ์ผ fetchingํ๋ฉด์ parsing 2) main.js ๋ค์ด๋ก๋ ์๋ฃ๋๋ฉด, parsing ๋ฉ์ถ๊ณ executing..