How do you check if an array is an array in JavaScript?
Use Array.isArray(x). typeof [] returns 'object', and [] instanceof Array can fail across frames/iframes. Array.isArray is the reliable way.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in JavaScript typeof and instanceof for undefined Checks
'undefined'. typeof undefined is 'undefined', and typeof an undeclared variable is also 'undefined' without throwing a ReferenceError. This makes typeof safe for feature detection.
No. undefined instanceof Object is false, and null instanceof Object is false. instanceof checks the prototype chain, which undefined and null do not have. Use instanceof only for objects.
It is a historical bug from the original implementation. null was represented with a type tag of 0, which the typeof check interpreted as object. It cannot be fixed without breaking existing code.
Still have questions?
Browse all our FAQs or reach out to our support team
