Use typeof for primitives and functions, Array.isArray() for arrays, and instanceof to check whether an object came from a given constructor or class.
typeof returns a string such as "number", "string" or "function". It has two traps. typeof null is "object", and so is typeof of any array, which is why arrays need Array.isArray(). To test for null itself, compare with === null.
instanceof walks the prototype chain, so it fails for objects created in another frame or window.
The most reliable general check is Object.prototype.toString.call(value), which returns labels such as "[object Date]" or "[object Null]".
typeof variable; // Returns string representation
Array.isArray(variable); // Check if array
variable instanceof Constructor; // Check instance type
Object.prototype.toString.call(variable); // Most reliable method
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓