What are the quirks of typeof, and how do you reliably check types?
Quick answer
`typeof null` is "object" and `typeof []` is "object". Use `Array.isArray`, `=== null`, or `Object.prototype.toString` for reliable checks.
In detail
`typeof` is fine for primitives and functions but can't distinguish arrays/objects/null. For robust checks: arrays → `Array.isArray(x)`, null → `x === null`, and a general tag via `Object.prototype.toString.call(x)` which returns strings like "[object Array]" or "[object Date]".
typeof [] // "object"
typeof null // "object"
typeof function(){} // "function"
Array.isArray([]) // true
Object.prototype.toString.call(new Date()) // "[object Date]"Why interviewers ask this: Type checking trips up people who only memorised typeof.
This is 1 of 118+ questions in the JavaScript Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the JavaScript Interview Kit → ₹299