강의

멘토링

커뮤니티

Inflearn Community Q&A

leh87671680's profile image
leh87671680

asked

ES6 course for modern javascript development

Solve Practice Example 1

타입 관련 궁금한 점이 있습니다.

Resolved

Written on

·

239

1

안녕하세요
 
toString.call()을 이용하여 타입을 확인할 수 있다고 했는데,
언제 사용하나요 ??
 
typeof()와 비교했을 때, 차이점이 무엇인가요?
es6javascript

Answer 1

1

typeof:

- 기본 데이터 타입(e.x. undefined, boolean, number, string, symbol, bigint, function)

- 객체 타입을 구분하는 데 제한적(배열과 일반 객체 모두 'object'로 반환)

Object.prototype.toString.call:

- 정확한 데이터 타입

- 객체의 정확한 내부 클래스 이름 반환 시(e.x. 배열, 정규 표현식, 날짜 등)

leh87671680's profile image
leh87671680

asked

Ask a question