Object.prototype.toString()
런타임에 타입 검사가 필요한 경우에는 사용을 고려해보자
typeof 연산자
typeof 연산자typeof null; // object
typeof []; // object
typeof {}; // object
typeof new Date(); // object
typeof /foo/; // object
typeof (() => {}); // functioninstanceof 연산자
instanceof 연산자function Car() {}
const car = new Car();
car instanceof Car; // ✅ true[] instanceof Array; // ✅ true
(() => {}) instanceof Function; // ✅ true
new Map() instanceof Map; // ✅ true
1 instanceof Number; // ❌ false
'foo' instanceof String; // ❌ falseObject.prototype.toString()
Object.prototype.toString()Last updated