What Are the Possible Results of typeof in JavaScript?
See all eight values typeof can return in JavaScript, why typeof null is object, and better checks for arrays, null and classes.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
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.
Arrays, objects, Maps and Sets cover most data storage in JavaScript. See examples, a comparison table and when to use each one.
The seven JavaScript primitive types with examples, typeof results, and how immutable primitives differ from objects.
JavaScript has seven primitive types, including bigint added in ES2020. See each type with examples, typeof results and how primitives differ from objects.
Strings are primitive, immutable values in JavaScript. See how auto-boxing gives them methods and why new String() should be avoided.
JavaScript primitives such as strings, numbers and booleans cannot be changed after creation. See examples, the const difference and how objects differ.
JavaScript strings are immutable primitives. See how they differ from String objects, how methods work on them and how to check types safely.
A complete reference to the seven JavaScript primitives with typeof results, ES versions and short code examples, plus how primitives differ from objects.
Java has eight primitive types: byte, short, int, long, float, double, char and boolean. See sizes, ranges and examples, and how JavaScript primitives differ.