const getUser = async ({ id, name }) => {
console.log(id, name);
};
const user = { id: 1, name: "abc" };
getUser(user); // ✅ { id, name } 구조 분해
-----
✅ 결과
1 abc
const getUser = async (id, name) => {
console.log(id, name);
};
getUser(1, "abc"); // ✅ 값 개별 전달
-----
✅결과
1 abc
const getUser = async (id, name) => {
console.log(id, name);
};
const user = { id: 1, name: "abc" };
getUser(user); // ❌ 오류 발생
❌ 오류 발생 (파라미터 id에 객체 전체가 전달됨!)
[object Object] undefined
const getUser = async ({ id, name }) => {
console.log(id, name);
};
getUser(1, "abc"); // ❌ 오류 발생
❌ 오류 발생 (기대하는 값이 객체인데, 개별 값이 전달됨!)
TypeError: Cannot destructure property 'id' of 'undefined'