isPrimitive - Functional

건네받은 값이 프리미티브 (primitive)인지 어떤지를 판정하는 boolean를 돌려준다.

  1. 프리미티브가 아닌 유형 문자열의 배열에 대하 Array.includes()를 돌려준다.
  2. typeof를 사용하여 유형을 제공한다.
  3. typeof null은 'object'로 평가되므로 직접 비교해야한다.
const isPrimitive = (val) => !['object', 'function'].includes(typeof val) || val === null

// 예시
isPrimitive(null) // true
isPrimitive(50) // true
isPrimitive('Hello!') // true
isPrimitive(false) // true
isPrimitive(symbol()) // true
isPrimitive([]) // false