Use instanceof for custom types:

var ClassFirst = function () {};
var ClassSecond = function () {};
var instance = new ClassFirst();
typeof instance; // object
typeof instance == 'ClassFirst'; // false
instance instanceof Object; // true
instance instanceof ClassFirst; // true
instance instanceof ClassSecond; // false 

Use typeof for simple built in types:

'example string' instanceof String; // false
typeof 'example string' == 'string'; // true

'example string' instanceof Object; // false
typeof 'example string' == 'object'; // false

true instanceof Boolean; // false
typeof true == 'boolean'; // true

99.99 instanceof Number; // false
typeof 99.99 == 'number'; // true

function() {} instanceof Function; // true
typeof function() {} == 'function'; // true

Use instanceof for complex built in types:

/regularexpression/ instanceof RegExp; // true
typeof /regularexpression/; // object

[] instanceof Array; // true
typeof []; //object

{} instanceof Object; // true
typeof {}; // object

And the last one is a little bit tricky:

typeof null; // object
Answer from Szymon Wygnański on Stack Overflow
🌐
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 - Note: Both arrays and objects return 'object' when using typeof. To differentiate between them, you might need additional checks. The instanceof operator checks if an object is an instance of a specific class or constructor function.
Discussions

type .kind checks vs. class instanceof checks
It looks like you're using the same example as the official documentation on Discriminated Unions , so I assume you've seen that section. Out of curiosity then, what makes you say this? However newer docs don't seem to ever show discriminated unions If you're looking to have discriminated unions like Rust, follow that section to roll your own or look for a library that's already implemented them. fp-ts has everything under the sun in a Haskell style, neverthrow has Rust-like Result and ResultAsync, and sum-types helps with the boilerplate of defining your own sum types. I wouldn't recommend instanceof checks, TypeScript just isn't designed to work well with nominal typing so it's not the best experience. More on reddit.com
🌐 r/typescript
21
24
May 8, 2022
instanceof, why not?

instanceof is usually code smell. As in, there is probably a better way to achieve the same thing.

For numbers and strings, typeof is a good option. For functions, duck typing is often a better choice than instanceof. So your code might look like this:

if (typeof obj.dispose === 'function')
    obj.dispose() 

constructor is unreliable and can be overridden easily. You should never rely on it to be a particular value.

More on reddit.com
🌐 r/javascript
16
8
September 26, 2014
Difference Between typeof and instanceof in JavaScript | Interview Question
JS gives you 2 keywords to verify the type of the value referred to by a reference. First of all, you have the typeof keyword. This keyword, used in the form of typeof will return a string that takes values from the following list: number string undefined object undefined symbol bigint boolean As we can see, typeof returns a primitive type. An interesting corner case is typeof null === 'object' surprisingly. Every class instance will also return 'object' on a typeof call. If you want to test for a specific class type, you have to use the instanceof keyword. The syntax is instanceof . What the aforementioned expression will return is a boolean value - true/false, if the class is part of the prototype chain. const m = new Map(); console.log(m instanceof Map) // true console.log(m instanceof Set) // false class MyMap extends Map { } const mm = new MyMap(); console.log(mm instanceof Map) // true console.log(mm instanceof MyMap) // true console.log(mm instanceof Set) // false More on reddit.com
🌐 r/Angular2
1
1
September 30, 2022
Can instanceOf operator be used to check if an object is an instance of a n interface, or type?
To add to what others have said already, there's a neat trick you can do in typescript to check if your instance is of a given "type". You declare it as an abstract class and implement the Symbol.hasInstance method. Example: abstract class Person { abstract readonly name: string; abstract readonly age: number; public static [Symbol.hasInstance](instance: unknown): instance is Person { if (instance === null || (typeof instance !== 'object' && !(instance instanceof Person))) return false; const name: unknown = (instance as any).name; const age: unknown = (instance as any).age; if (typeof name !== 'string' && !(name instanceof String)) return false; return typeof age === 'number' || age instanceof Number; } } Then you can use it as: const person = { name: "SomeName", age: 55 }; const noPerson = { weight: "300kg" }; console.log(person instanceof Person); // will print true console.log(noPerson instanceof Person); // will print false The advantage of this method in my opinion is that because typescript has a structure typing system, you can just do: class PersonImpl implements Person { constructor( readonly name: string, readonly age: number ) { } } console.log(new PersonImpl("SomeName", 55) instanceof Person); // will also print true This way, if you make a typo on PersonImpl you will know immediately that it's wrong and at runtime you can still type check. More on reddit.com
🌐 r/typescript
10
5
August 10, 2023
🌐
DEV Community
dev.to › imranmind › javascript-interview-trick-typeof-vs-instanceof-3jlb
JavaScript Interview Trick: typeof vs instanceof - DEV Community
April 29, 2025 - Use 'typeof' when you want to know the type of a primitive value. Use 'instanceof' when you want to know if an object is an instance of a certain class.
🌐
Medium
medium.com › @AlexanderObregon › the-mechanics-behind-javascripts-typeof-and-instanceof-3299ff38f20a
The Mechanics of JavaScript’s typeof and instanceof | Medium
May 16, 2025 - That’s why typeof returns "object" instead of "string" here. This kind of thing doesn't happen often in modern code, but it can show up in older codebases or libraries. You can usually avoid boxed primitives altogether. Most of the time, they only create confusion without much benefit. The instanceof operator looks like a way to ask if something was created by a particular constructor.
🌐
Zhihu
zhihu.com › en › answer › 3191769130
In JavaScript, what is the difference between `typeof` and ` ...
知乎,中文互联网高质量的问答社区和创作者聚集的原创内容平台,于 2011 年 1 月正式上线,以「让人们更好的分享知识、经验和见解,找到自己的解答」为品牌使命。知乎凭借认真、专业、友善的社区氛围、独特的产品...
🌐
Dmitri Pavlutin
dmitripavlutin.com › javascript-typeof-instanceof
Type checking in JavaScript: typeof and instanceof operators
November 24, 2020 - 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....
Find elsewhere
🌐
Azurewebsites
benchmarklab.azurewebsites.net › Benchmarks › Show › 7368 › 0 › typeof-vs-instanceof-function
Benchmark: typeof vs instanceof Function - MeasureThat.net
Function: typeof vs instanceof · typeof vs instanceof vs null · typeof vs instanceof Function vs call · instanceof vs typeof function · Comments · Do you really want to delete benchmark?
🌐
YouTube
youtube.com › watch
Difference Between typeof and instanceof in JavaScript | Interview Question - YouTube
Please like, share and subscribe if you found the video useful. Checkout the Playlists: 👉 FrontEnd JavaScript Interview Questions: https://www.youtube.com/w...
Published   September 28, 2022
🌐
MeasureThat
measurethat.net › Benchmarks › Show › 7367 › 0 › instanceof-vs-typeof
Benchmark: instanceof vs typeof - MeasureThat.net
instanceof vs typeof vs fast typeof object · instanceof vs typeof for objects · JS instanceof vs in · instanceof vs typeof gyuguyguy · instanceof vs typeof franco · Comments · × · Do you really want to delete benchmark? Cancel Delete · × · FAQ: FAQ ·
🌐
DanyWalls
danywalls.com › how-to-check-types-in-typescript
How To Check Types In Typescript | DanyWalls
August 10, 2022 - In Typescript, we have three ways to work with it using: typeof: the keyword helps to check value types, like boolean, string, number, etc. instanceof: the keyword to compare the object instance with a class constructor.
🌐
sebhastian
sebhastian.com › instanceof-javascript
The JavaScript instanceof operator explained - with syntax and examples | sebhastian
March 24, 2022 - The instanceof returns either true or false while the typeof returns the actual type name of the value.
🌐
Fatalerrors
fatalerrors.org › a › the-difference-between-typeof-and-instanceof-in-js.html
The difference between typeof and instanceof in JS
September 3, 2021 - 01: typeof is often used to determine the type of a variable, which can be a variable of basic data type / a variable of object data type. instanceof is only used to determine whether an object is an instance of the specified object data type.
🌐
Codegrepper
codegrepper.com › code-examples › whatever › typeof+vs+instanceof+js
instanceof vs typeof - Code Examples & Solutions
May 9, 2021 - For JS/TS: instanceof checks the proptype chain and typeof compares against string literal labels. - use instanceof for custom types - use typeof for simple built in types - Use instanceof for complex built in types if in doubt go with instanceof, tbh