Type(타입)
내장 타입
- null
- undefined
- boolean
- number
- string
- object
- symbol (ES6부터 추가)
타입은 typeof 연산자로 알 수 있다.
typeof undefned === 'undefined';
typeof true === 'boolean';
typeof 42 === 'number'
typeof '42' === 'string'
typeof { life: 42 } === 'object'
typeof Symbol() === 'symbol'
typeof null === 'object'
- null은 falsy한 유일한 원시 값이지만 type으 'object'인 특별한 존재
- null 같은 경우는 버그이지만 20년 동안 해결되지 않았고 현재 수정이 이루어지면 다른 버그가 생겨서 잘 돌아가던 웹 소프트웨어가 멈출 수 있어 앞으로도 해결될 가능성은 낮아 보인다.
var a = null;
(!a && typeof a === 'object');
- typeof function
- function은 object의 하위타입!
- 최상위 내장타입이 아니다.
- 함수는 호출 가능한 객체(Callable Object)로 내부 프로퍼티 [[Call]]을 가진다.
console.log(typeof function a() {} === 'function');
- array 역시 object의 하위타입!
- 키가 숫자 인덱스
- length 프로퍼티가 자동으로 관리되는 등의 추가 특성을 지닌다.