jQuery jQuery.type() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Type detect

What You’ll Learn

The jQuery.type() utility returns a lowercase string naming the kind of value you pass in — fixing typeof traps like null and arrays. This tutorial covers syntax, all return values, five worked examples, comparisons with typeof and Array.isArray(), and when to branch on type in jQuery plugins.

01

Syntax

$.type(obj)

02

String

Type name out

03

null

Not “object”

04

array

Real arrays

05

date

Date objects

06

regexp

RegExp objects

Introduction

JavaScript’s built-in typeof operator is quick but unreliable for several common values. typeof null returns "object". typeof [] also returns "object". Dates and regular expressions look like ordinary objects too.

jQuery provides jQuery.type() (also written $.type()) as a static utility that inspects values with the same internal logic jQuery uses throughout its own codebase. The result is a predictable lowercase string you can compare in if statements or plugin option validators.

Understanding the jQuery.type() Method

jQuery.type(obj) uses Object.prototype.toString under the hood and maps internal class tags to friendly names. It returns "null" for null, "array" for arrays, "date" for Date instances, and "regexp" for RegExp objects — cases where typeof misleads beginners.

The method accepts any JavaScript value: primitives, functions, DOM nodes, jQuery collections, and plain objects. Use it when you need one consistent type string across a jQuery project, especially before calling utilities like $.extend() or iterating with $.each().

💡
Beginner Tip

Compare the return value with strict equality: $.type(value) === "array". jQuery always returns lowercase strings — never rely on loose checks.

📝 Syntax

General form of jQuery.type:

jQuery
jQuery.type( obj )
// or
$.type( obj )

Parameters

  • obj — any JavaScript value to inspect.

Return value

  • A lowercase string: "undefined", "null", "boolean", "number", "string", "function", "array", "date", "regexp", or "object".

Minimal workflow

jQuery
if ($.type(options) === "object") {
  settings = $.extend({}, defaults, options);
}

⚡ Quick Reference

Value$.type()typeof
undefined"undefined""undefined"
null"null""object"
true"boolean""boolean"
42"number""number"
"hi""string""string"
[]"array""object"
new Date()"date""object"
/re/"regexp""object"
{}"object""object"

📋 $.type vs typeof vs Array.isArray

Three tools for inspecting values — different precision and scope.

$.type
type string

null, array, date, regexp — jQuery accurate

typeof
operator

Fast primitives; null/array quirks

isArray
true / false

Arrays only — boolean check

$.isArray
boolean

Same as $.type(x) === "array"

Examples Gallery

Each example uses $.type(). Open DevTools or use the Try-it links to run them interactively.

📚 Getting Started

Walk through every documented return value — the official jQuery API pattern.

Example 1 — Inspect Every Basic Type

Loop over representative values and log what $.type() reports for each.

jQuery
var checks = [
  [undefined, "undefined"],
  [null,      "null"],
  [true,      "boolean"],
  [3,         "number"],
  ["test",    "string"],
  [function () {}, "function"],
  [[],        "array"],
  [new Date(), "date"],
  [/test/,    "regexp"],
  [{},        "object"]
];

checks.forEach(function (pair) {
  console.log($.type(pair[0]) === pair[1]); // all true
});
Try It Yourself

How It Works

This mirrors the jQuery API documentation demo: each value maps to exactly one expected string. Memorize this table and you will rarely be surprised by runtime type checks.

📈 Practical Patterns

Fix typeof traps, distinguish collections, and validate plugin options.

Example 2 — null Is Not "object"

The classic JavaScript gotcha — typeof null lies, but $.type does not.

jQuery
console.log(typeof null);    // "object"  — misleading!
console.log($.type(null));   // "null"    — correct

if ($.type(value) === "null") {
  console.log("Value is explicitly null");
}
Try It Yourself

How It Works

When validating API responses or form fields, distinguishing null from a plain object matters. $.type gives you a dedicated "null" string instead of lumping it with objects.

Example 3 — Distinguish Arrays from Plain Objects

Both look like objects to typeof, but jQuery separates them cleanly.

jQuery
var list = ["a", "b", "c"];
var map  = { 0: "a", 1: "b", length: 2 };

console.log(typeof list);       // "object"
console.log($.type(list));      // "array"
console.log($.type(map));       // "object" — array-like but not an array
Try It Yourself

How It Works

True arrays pass the internal [object Array] test. Array-like objects with a length property but no array prototype still report "object". For those, use $.makeArray() if you need array behavior.

Example 4 — Detect Date and RegExp Objects

Special object types that typeof cannot name — jQuery can.

jQuery
var when = new Date();
var pattern = /^\d+$/;

console.log($.type(when));     // "date"
console.log($.type(pattern));  // "regexp"
console.log(typeof when);      // "object" — not specific enough
Try It Yourself

How It Works

Plugin code that accepts callbacks, option objects, or date strings often needs to branch: serialize a Date differently from a plain object, or compile a string only when the input is not already a RegExp.

Example 5 — Route Plugin Options by Type

A practical handler pattern — strings select elements, objects merge settings, functions become callbacks.

jQuery
function initPlugin(target) {
  var t = $.type(target);

  if (t === "string") {
    return $(target);           // CSS selector
  }
  if (t === "function") {
    return target;              // ready callback
  }
  if (t === "object") {
    return $.extend({}, target); // settings object
  }
  return null;
}

console.log(initPlugin("#menu") instanceof jQuery); // true (if #menu exists)
console.log($.type(initPlugin({ speed: 300 })));   // "object"
Try It Yourself

How It Works

jQuery’s own plugins historically overloaded arguments — a string selector, a config object, or a function. $.type is the clean switch that decides which path to take without fragile typeof chains.

🚀 Common Use Cases

  • Plugin option validation — accept objects, strings, or functions and route each correctly.
  • Null-safe merging — detect null before passing data to $.extend().
  • Array vs object guards — iterate with $.each only after confirming the collection type.
  • Date serialization — format Date instances differently from plain config objects.
  • RegExp handling — skip re-compiling when input is already a regular expression.
  • Legacy jQuery codebases — one consistent type string across IE-era projects.

🧠 How jQuery.type() Classifies a Value

1

Handle null

If the value is strictly null, return "null" immediately.

null
2

Read class tag

Call Object.prototype.toString to get an internal tag like [object Array].

toString
3

Map to name

Translate known tags to lowercase strings: array, date, regexp, boolean, number, string, function.

Map
4

Return string

Unrecognized objects fall back to "object". Primitives map to their typeof equivalents.

📝 Notes

  • Available since jQuery 1.4 — powers many internal jQuery type checks.
  • Return values are always lowercase English strings.
  • DOM elements and jQuery objects typically return "object" — use dedicated checks for those.
  • Array-like objects (NodeList, arguments) are "object", not "array".
  • NaN has type "number" — same as any other number per JavaScript rules.
  • Related helpers: $.isArray(), $.isFunction(), $.isPlainObject(), $.isEmptyObject().

Browser Support

jQuery.type() has been part of jQuery since jQuery 1.4+. It works wherever jQuery runs — all modern browsers and legacy IE when paired with a supported jQuery build.

jQuery 1.4+

jQuery jQuery.type()

Supported in jQuery 1.x, 2.x, and 3.x. Behavior is consistent across browsers because jQuery owns the classification logic.

100% With jQuery loaded
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
jQuery.type() Universal

Bottom line: Safe in any project that already includes jQuery. Without jQuery, combine typeof, Array.isArray(), and optional Object.prototype.toString checks.

Conclusion

The jQuery.type() utility returns an accurate lowercase type string for any JavaScript value. It fixes the worst typeof traps — null, arrays, dates, and regexps — and gives plugin authors a reliable way to branch on input.

Compare results with strict equality, pair with specialized helpers like $.isPlainObject() when needed, then explore jQuery.isArray() for focused boolean array checks.

💡 Best Practices

✅ Do

  • Compare with === "array", === "null", etc.
  • Use $.isArray() when you only need a boolean
  • Validate plugin options with $.type before merging
  • Combine with $.isPlainObject() for config objects
  • Prefer native Array.isArray() in jQuery-free code

❌ Don’t

  • Rely on typeof null === "object" for null checks
  • Assume array-like objects return "array"
  • Use $.type alone to detect jQuery collections
  • Compare case-insensitively — results are always lowercase
  • Over-use type strings when a dedicated helper exists

Key Takeaways

Knowledge Unlocked

Five things to remember about jQuery.type()

Classify values the jQuery way.

5
Core concepts
🔴 02

null

Not object

Fix
🗃 03

array

True arrays

Detect
📅 04

date

Special obj

Extra
🔄 05

===

Strict cmp

Pattern

❓ Frequently Asked Questions

jQuery.type(obj) returns a lowercase string describing the kind of value passed in — such as "array", "boolean", "date", "function", "null", "number", "object", "regexp", "string", or "undefined". It fixes common typeof surprises.
typeof null returns "object" and typeof [] returns "object". jQuery.type(null) returns "null" and jQuery.type([]) returns "array". jQuery.type also recognizes "date" and "regexp", which typeof cannot distinguish from plain objects.
A jQuery DOM collection is an object, so $.type($("div")) typically returns "object". To test for a jQuery object specifically, use $.isFunction(obj.jquery) or check for the jQuery constructor — not $.type alone.
The documented return values are: undefined, null, boolean, number, string, function, array, date, regexp, and object. Anything else that is an object falls through to "object" unless it matches one of the special internal tags.
jQuery.isArray(obj) is a convenience wrapper equivalent to jQuery.type(obj) === "array". Use isArray when you only need a boolean; use type when you need the full type name for branching logic.
Use $.type() in jQuery codebases that must handle null, arrays, dates, or regexps reliably across older browsers. In jQuery-free modern JavaScript, Array.isArray(), optional chaining, and pattern matching often replace manual type strings.
Did you know?

jQuery’s internal type detection powers not only $.type() but also helpers like $.isFunction() and $.isArray(). Before jQuery 1.4, developers copied brittle Object.prototype.toString snippets by hand — jQuery.type packaged that logic into one reliable utility.

Continue to jQuery.isArray()

Test whether a value is a true JavaScript array with a simple boolean check.

isArray() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful