No Login Data Private Local Save

JavaScript Type Checker - Online Typeof & Instanceof Sandbox

18
0
0
0

JavaScript Type Checker – Online typeof & instanceof Sandbox

Test any JavaScript expression and instantly see its typeof result and instanceof inheritance chain. Understand the quirks of JavaScript types in a live sandbox.

Expression

Quick examples:

Result


          
typeof:

instanceof Checks

ConstructorResult

Only built‑in constructors available in your browser are shown.

Frequently Asked Questions

typeof is a unary operator that returns a string indicating the primitive type of its operand. It can distinguish between 'undefined', 'boolean', 'number', 'string', 'symbol', 'function', and 'object'. However, it has known limitations (e.g., typeof null returns 'object', and it cannot differentiate an array from a plain object).

This is a long‑standing bug in JavaScript, originating from its first implementation. The internal type tag for null was 000, which coincided with the tag for objects. The behavior was kept for backward compatibility. To reliably check for null, use value === null.

typeof [] returns "object". To properly detect arrays, use Array.isArray(value) or value instanceof Array, both of which are much more reliable.

  • typeof checks the primitive type (or function/object) of a value and returns a string.
  • instanceof tests whether the prototype property of a constructor appears anywhere in the prototype chain of an object. It only works with objects and checks inheritance.
Example: typeof [] === 'object' but [] instanceof Array is true.

No. instanceof requires an object on the left side. Primitives like numbers, strings, or booleans will always return false (e.g., 42 instanceof Number is false). However, primitives are temporarily wrapped in objects when you access methods, but instanceof sees the primitive.

The most robust method is Array.isArray(value). Alternatively, you can use value instanceof Array, but it may fail across different execution contexts (e.g., iframes). Our sandbox shows both methods.

NaN (Not‑a‑Number) is technically a numeric value according to the IEEE 754 floating‑point standard. JavaScript follows this specification. To check if a value is NaN, use Number.isNaN(value) or isNaN(value), though the latter coerces the argument.

Use typeof x === 'undefined'. This is the only safe way to check if a variable is declared but not defined, because accessing an undeclared variable throws a ReferenceError, while typeof never throws.

It always returns false. null and undefined are not objects, so they cannot be on the left side of instanceof (technically, the instanceof operator first coerces the left operand to an object, but the internal check fails for these values and returns false).

No. typeof cannot distinguish between different object subtypes such as Array, Date, RegExp, Map, or custom classes; all return "object". For those, you need instanceof or other specialized methods like Array.isArray().