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
Fundamentals
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.
Concept
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.
Foundation
📝 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".
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.
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
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
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"
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.
Applications
🚀 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.
Important
📝 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().
Compatibility
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 ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll 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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about jQuery.type()
Classify values the jQuery way.
5
Core concepts
📄01
$.type
Type string
API
🔴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.