Truthy & Falsy
let a = "string" //True
let a = [] //True
let a = ""; //False
let a = null; //False
let a = undefined //False
let a = 0; //False
const meal = {
한식: "불고기",
중식: "멘보샤",
일식: "초밥",
양식: "스테이크",
};
const getMeal = (mealType) => {
return meal[mealType] || "굶기";
};
let arr = ["one", "two", "three"];
let [one, two, three] = arr;
console.log(one, two, three);
let a =10;
let b = 20;
[a,b] = [b,a];
console.log(a,b)
const cookie = {
base: "cookie",
madeIn: "korea",
};
const chocochipCookie = {
...cookie, //객체의 프로퍼티를 펼쳐줌
toping: "chocochip",
};
const allCookies = [...noTopingCookies, ...topingCookies];

Promise

function taskA(a) {
return new Promise((resolve, reject) => {
setTimeout(() => {
const res = a * 2;
resolve(res);
}, 1000);
});
}
이 함수는 비동기 작업을 하고, 그 반환값을 promise 로 반환받아서 사용할 수 있다
그리고 then을 사용해서 적용.
... 근데 좀 어려워ㅜ
함수안에 매개변수로 함수넣기!
안정적으로 순차실행이 되게 해준다.
근데 코드가 길어지면 이해가 어려워...
=> Promise 를 사용하자!
async & await
async function helloAsync() {
await delay(3000);
return "hello asynce";
}
async function main() {
const res = await helloAsync();
console.log(res);
}
main();

promise = 비동기 처리를 하는 함수.
이 처리의 함수결과는 then 을 통해서 사용
async function getData(){
let rawResponse = await fetch("https://jsonplaceholder.typicode.com/posts");
let jsonResponse = await rawResponse.json();
console.log(jsonResponse);
}
getData();