JavaScriptBeginner#types

What is the difference between typeof and instanceof?

typeof returns a primitive type string and reports 'object' for arrays and null. instanceof walks the prototype chain to test constructor lineage, so use Array.isArray for arrays.

Example
typeof [];             // 'object'
[] instanceof Array;   // true
Array.isArray([]);     // true

Related Questions

1
JavaScriptIntermediate#fundamentals

What is strict mode?

Open
2
JavaScriptBeginner#fundamentals#types

What are the data types in JavaScript?

Open
3
JavaScriptBeginner#scope#es6

Difference between var, let and const?

Open