// null과 undefined
const neesArgs = (a, b, c, d) => {
const obj ={a,b,c,d};
let result = {}
for (let key in obj){
if (obj[key] !== undefined && obj[key] !== null){
result[key] = obj[key];
console.log(result);
}
}
return result
}
neesArgs(1, null, 3);
// { a: 1, c: 3 }
같은 듯 다른 null과 undefined에 대해 알아보자.
null & undefined 는 원시데이터타입(Primitive data type)에 속한다.console.log(typeof null)
// 'Object'
null은 개발자가 빈값이라고 지정한 상태, 비어있는, 존재하지 않는 값null을 typeof 키워드를 활용해 콘솔에 출력해보자. Object라고 출력된다.null인지 확인하기 위해서는 typeof 키워드가 아닌 null 자체와 같은지를 체크하자!console.log(typeof undefined)
// 'undefined'
undefined는 값이 초기화, 할당되지 않았을때의 상태undefined을 typeof 키워드를 활용해 콘솔에 출력해보자. undefined라고 출력된다.typeof 키워드를 활용해 유효검사를 한다면 문자열 'undefined'로 비교해야 한다!