How to get the type of object in JavaScript?
typeof, Array.isArray, instanceof and Object.prototype.toString each answer a different question. See which one to use and which pitfalls to avoid.
466 posts about JavaScript: questions with answers, tutorials and articles, newest first.
typeof, Array.isArray, instanceof and Object.prototype.toString each answer a different question. See which one to use and which pitfalls to avoid.
Check the type of any JavaScript value with typeof, Array.isArray(), instanceof and Object.prototype.toString, and learn the quirks to watch for.
Learn how to check the type of an array item with typeof and instanceof, and how to identify DOM elements with tagName, nodeType, matches and instanceof.
JavaScript has seven primitive types and one object type. This guide covers each type, typeof results, and the difference between value and reference.
Learn which JavaScript check to use for each data type: typeof for primitives, Array.isArray for arrays, instanceof for classes, and a toString helper for everything.
Inside a function, typeof arguments is object, because arguments is array-like but not an array. Learn conversion, rest parameters and arrow function limits.
JavaScript functions are written as declarations, expressions or arrow functions. See how they differ in hoisting, this binding and constructors, with examples.
typeof returns lowercase "string" for string primitives, but "object" for String wrapper objects. Examples and safe string checks.
See all eight values typeof can return in JavaScript, why typeof null is object, and better checks for arrays, null and classes.
typeof returns "function" for every callable value, classes included. See the full list of typeof results and how to guard callbacks.
typeof returns the string function for every callable value, from arrow functions to classes. Learn the full typeof table and safe callback checks.
typeof undefined returns the string undefined, even for undeclared names. See when values are undefined and how to check for it in modern JavaScript.
Use typeof, instanceof, Array.isArray and Object.hasOwn to check whether a variable, class or property exists in JavaScript, and avoid the null and TDZ traps.
Use typeof for primitives, then add checks for null, arrays and objects. Includes instanceof, Object.prototype.toString and a reusable getType helper.
Compare typeof to a type-name string inside an if statement. Learn every return value and how to handle null, arrays, NaN and undeclared variables.
Object is JavaScript's only non-primitive type, and arrays, functions, dates and RegExp are all objects. See how references, copying and comparison differ.
Primitives are immutable values compared by value, while objects are handled by reference. See the practical differences in copying, comparing and mutating, with examples.
JavaScript has no separate float type; all numbers are 64-bit doubles. Learn the precision limits, safe comparisons, BigInt and how to handle money.
Date is a reference type that wraps a millisecond timestamp. See how to create, copy, compare, validate and format dates without common bugs.
Learn how to tell primitive values from objects in JavaScript and how copying, equality and freezing differ, including shallow versus deep copies.