Data Type

데이터 타입을 확인하는 과정에서 typeof를 통해 데이터 타입을 확인할 수가 있는데,

Untitled

null, { } , [ ] 은 데이터 타입이 객체로 인식하고 타입에대해 명확하지 않다.

이는 앞으로 프론트엔드를 작업시에 객체로 작업하는 경우가 상당수 있기 때문에

객체에 대한 데이터 타입을 확인할 필요가 생길때는

function getType(data) {
  return Object.prototype.toString.call(data).slice(8, -1)
}

getType이라는 로직을 만들어주고 적용해주면

console.log(getType(123))
console.log(getType(false))
console.log(getType(null))
console.log(getType({}))
console.log(getType([]))

Untitled

객체에 대한 타입 함수도 확인할 수 있다.

export default function getType(data) {
  return Object.prototype.toString.call(data).slice(8, -1)
}

getType을 별도로 JS파일을 만들어줘서