If typeof x === 'object', x is an object (except a function) or null. If you want null, arrays, and functions to be excluded, just make it:

Copytypeof x === 'object' && !Array.isArray(x) && x !== null
Answer from Chuck on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › typeof
typeof - JavaScript | MDN
1 month ago - The type tag for objects was 0. null was represented as the NULL pointer (0x00 in most platforms). Consequently, null had 0 as type tag, hence the typeof return value "object".
🌐
W3Schools
w3schools.com › js › js_typeof.asp
JavaScript typeof
This is a well-known bug in JavaScript and has historical reasons. A complex data type can store multiple values and/or different data types together. ... All other complex types like arrays, functions, sets, and maps are just different types of objects. ... typeof {name:'John'} // Returns object typeof [1,2,3,4] // Returns object typeof new Map() // Returns object typeof new Set() // Returns object typeof function (){} // Returns function Try it Yourself »
🌐
CoreUI
coreui.io › blog › what-is-the-difference-between-typeof-and-instanceof-in-javascript
What is the difference between typeof and instanceof in JavaScript · CoreUI
September 17, 2024 - const empty = null console.log(typeof empty) // 'object' Explanation: This is a historical bug in JavaScript.
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › typeof-types.html
TypeScript: Documentation - Typeof Type Operator
JavaScript already has a typeof operator you can use in an expression context: ts · // Prints "string" console. log(typeof "Hello world");Try · TypeScript adds a typeof operator you can use in a type context to refer to the type of a variable or property: ts ·
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-array-typeof
JavaScript Typeof for Data Types: Array, Boolean and More | Built In
Summary: The typeof operator in JavaScript checks a value’s data type, returning strings like "string", "number" or "object". While useful, it has quirks — like returning "object" for null and arrays. For full accuracy, extra methods may be needed for arrays, dates, and regex.
Find elsewhere
🌐
DEV Community
dev.to › kathirvel-s › why-typeof-returns-object-in-javascript-59n7
Why typeof( [ ] ) Returns "object" in JavaScript - DEV Community
March 4, 2026 - In JavaScript,typeof only returns one of these values: "undefined" "boolean" "number" "string" "bigint" "symbol" "function" "object"
🌐
Medium
piyush-dubey.medium.com › advanced-guide-to-javascript-typeof-operator-d88eb12f0ff0
Advanced Guide to JavaScript typeof Operator | by Piyush | Medium
September 22, 2024 - ... Where operand is the value whose type you want to check. typeof returns a string that represents the type of the operand. console.log(typeof 42); // "number" console.log(typeof 'Hello World'); // "string" console.log(typeof true); // "boolean" ...
🌐
John Kavanagh
johnkavanagh.co.uk › home › articles › javascript's typeof operator: uses and limitations
JavaScript's typeof Operator: Uses and Limitations | John Kavanagh
April 10, 2026 - This is where typeof starts to show it's age. With the evolution of JavaScript (i.e., ES6 and beyond), newer data structures have been introduced like Map, Set, or Symbol. typeof does not distinguish these newer types and often returns 'object' or 'symbol'.
🌐
Medium
medium.com › @AlexanderObregon › the-mechanics-behind-javascripts-typeof-and-instanceof-3299ff38f20a
The Mechanics of JavaScript’s typeof and instanceof | Medium
May 16, 2025 - Internally, they’re still objects with properties and a prototype. But typeof checks whether the value can be called, and if it can, it returns "function". It’s a special case that exists just to make typeof a little more useful in day-to-day code. That said, not everything callable is a function in the traditional sense. In newer JavaScript versions you can have async generator functions or callable Proxy objects.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-typeof-how-to-check-the-type-of-a-variable-or-object-in-js
JavaScript TypeOf – How to Check the Type of a Variable or Object in JS
November 9, 2020 - typeof 0; //'number' typeof +0; //'number' typeof -0; //'number' typeof Math.sqrt(2); //'number' typeof Infinity; //'number' typeof NaN; //'number', even if it is Not a Number typeof Number('100'); //'number', After successfully coerced to number typeof Number('freeCodeCamp'); //'number', despite it can not be coerced to a number typeof true; //'boolean' typeof false; //'boolean' typeof Boolean(0); //'boolean' typeof 12n; //'bigint' typeof ''; //'string' typeof 'freeCodeCamp'; //'string' typeof `freeCodeCamp is awesome`; //'string' typeof '100'; //'string' typeof String(100); //'string' typeof
🌐
Tabnine
tabnine.com › home › how to use the typeof operator in javascript
How to Use the typeof operator in JavaScript - Tabnine
July 25, 2024 - The typeof operator accepts an operand and returns the type of the provided operand as a string. The following sample code shows the typeof operator in use: const str = 'Im a string'; console.log(typeof str); // Expected output: string In the ...
🌐
freeCodeCamp
forum.freecodecamp.org › t › a-question-about-typeof-operator-in-js › 406846
A question about typeof operator in JS - The freeCodeCamp Forum
June 22, 2020 - Hello everyone. I’m curious to sort out a little curiosity about the typeof operator in JS. The typeof operator defines the type of a value/variable. My question is: why so? Isn’t that obvious?
🌐
DEV Community
dev.to › pestrinmarco › typeof-array-is-an-object-in-javascript-1p6k
Typeof array is an object in javascript - DEV Community
March 3, 2021 - in javascript all derived data type is always a type object. Included functions and array. Tagged with javascript, angular, frontend.
🌐
Reddit
reddit.com › r/javascript › why is `typeof null === 'object'` in javascript? the 30-year story of a bug we can't fix
r/javascript on Reddit: Why is `typeof null === 'object'` in JavaScript? The 30-year story of a bug we can't fix
October 14, 2025 - It comes down to the abstraction level. "number" in JavaScript and "number" in IEEE754 are not the same thing, despite sharing the same name. typeof NaN === "number", here number refers to JavaScript type, whereas the last N in NaN refers to IEEE754 number.
🌐
Dmitri Pavlutin
dmitripavlutin.com › javascript-typeof-instanceof
Type checking in JavaScript: typeof and instanceof operators
JavaScript is a loosely-typed language, ... you have to check what type the variable has. typeof expression is the operator that lets you determine the type of expression....
🌐
Tutorial Teacher
tutorialsteacher.com › articles › how-to-get-type-of-object-in-javascript
How to get the type of an object in JavaScript?
The typeof operator also returns the object type created with the "new" keyword. ... var obj = new String(); var str = "this is string"; typeof obj; // returns object typeof str; // returns string
🌐
Pi My Life Up
pimylifeup.com › home › how to use the typeof operator in javascript
How to use the typeof Operator in JavaScript - Pi My Life Up
July 6, 2022 - A primitive data type is a base variable type such as a string, number, Boolean, etc. The typeof operator will return the data type of the operand as a string. With the table below, you can quickly see the strings that the typeof operator in ...
🌐
Open Graph
ogp.me
The Open Graph protocol
In order for your object to be represented within the graph, you need to specify its type.