jQuery isEmptyObject() Method

Beginner
6 min read
Updated: Oct 2026
4 examples
Live preview

What Is isEmptyObject()?

jQuery.isEmptyObject(object) (alias $.isEmptyObject) returns true when the object has no enumerable properties (since jQuery 1.4). Empty {} is true; any key makes it false.

Remember
$.isEmptyObject(object)  → true | false

$.isEmptyObject({})                 // true
$.isEmptyObject({ foo: "bar" })     // false

// Official guidance: plain objects only
$.isPlainObject(obj) && $.isEmptyObject(obj)
NeedUse
No enumerable keys?$.isEmptyObject(obj)
Is it a plain object?$.isPlainObject(obj)
Own keys only (native)Object.keys(obj).length === 0
Merge defaults$.extend({}, defaults, opts)

How to Use isEmptyObject()

Pass a plain object, then branch on empty vs has keys.

  1. Start with a plain object (options, config, API payload).
  2. Optionally confirm with $.isPlainObject(obj).
  3. Call $.isEmptyObject(obj).
  4. If true, treat as “no settings”; if false, read or merge the keys.
PieceRequired?Role
objectYesPlain object to test
Return—Boolean
Since 1.4—Also sees inherited enumerable props

Pseudocode

Pseudocode
function isEmptyObject(object):
    for each enumerable key in object:   // for...in
        return false
    return true

// Typical options pattern:
if isEmptyObject(userOptions):
    settings = defaults
else:
    settings = extend({}, defaults, userOptions)

Cheat Sheet

Keep these facts handy while checking empty objects.

TopicDetail
SyntaxjQuery.isEmptyObject(object)
SincejQuery 1.4
Empty{} → true
Has keys{ foo: "bar" } → false
InputPlain object (recommended)
vs Object.keysOwn props only vs for...in (incl. inherited)
Pair with$.isPlainObject()

Live Preview

Test a few plain objects with $.isEmptyObject.

Browser demo of $.isEmptyObject() — same idea as the examples below.

Result
object = {}
$.isEmptyObject(object) → true

jQuery Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Official Empty vs Non-Empty

The classic true/false pair from the jQuery docs.

jQuery
console.log($.isEmptyObject({}));              // true
console.log($.isEmptyObject({ foo: "bar" }));  // false
Try It Yourself

How It Works

  1. Empty literal. {} has no enumerable keys → true.
  2. One property. foo is enumerable → false.
  3. Return type. Always a boolean — easy for if guards.
  4. Use case. Detect “user passed no options” quickly.

Example 2 — Defaults When Options Are Empty

Skip merging when the caller passed {}.

jQuery
var defaults = { theme: "light", size: 16 };
var userOptions = {};
var settings;

if ($.isEmptyObject(userOptions)) {
  settings = defaults;
} else {
  settings = $.extend({}, defaults, userOptions);
}

console.log(settings.theme);  // "light"
Try It Yourself

How It Works

  1. Defaults. Plugin starts with a full settings object.
  2. Empty check. userOptions is {} → isEmptyObject is true.
  3. Skip merge. Reuse defaults directly.
  4. Otherwise. Use $.extend when options have keys.

Example 3 — Compare with Object.keys

Own-property count is a common native twin.

jQuery
var a = {};
var b = { x: 1 };

console.log($.isEmptyObject(a));                 // true
console.log(Object.keys(a).length === 0);        // true

console.log($.isEmptyObject(b));                 // false
console.log(Object.keys(b).length === 0);        // false
Try It Yourself

How It Works

  1. Plain literals. Both APIs agree on {} and { x: 1 }.
  2. Object.keys. Counts only own enumerable properties.
  3. isEmptyObject. Uses for...in (can include inherited enumerable keys).
  4. Choice. Prefer Object.keys when you only care about own keys.

Example 4 — Guard with isPlainObject

Follow the docs: confirm “plain object” before the empty check.

jQuery
function isEmptyPlain(obj) {
  return $.isPlainObject(obj) && $.isEmptyObject(obj);
}

console.log(isEmptyPlain({}));           // true
console.log(isEmptyPlain({ a: 1 }));     // false
console.log(isEmptyPlain([]));           // false (not plain object)
Try It Yourself

How It Works

  1. First gate. $.isPlainObject rejects arrays and host objects.
  2. Second gate. $.isEmptyObject checks for enumerable keys.
  3. Empty plain. Only {} (and similar) returns true.
  4. Array. [] fails the plain-object test → false.

Edge Cases & Pitfalls

Check these before trusting empty-object results.

input

Plain objects only

DOM elements, strings, and host objects may not be consistent across browsers. Pair with $.isPlainObject().

null

null / undefined can throw

Normalize first: var opts = options || {}, then call $.isEmptyObject(opts).

nested

Nested empty ≠ outer empty

{ user: {} } has a key — result is false. Empty means no enumerable keys at that object level.

prototype

Inherited enumerable keys count

Since 1.4, for...in can see prototype properties. For own keys only, use Object.keys(obj).length === 0.

Browser Support

jQuery.isEmptyObject() is available since jQuery 1.4+ in all browsers that load jQuery. It is a data utility — no special DOM API required.

✓ jQuery 1.4+ · All browsers with jQuery

jQuery.isEmptyObject()

Works wherever jQuery runs in the browser. For own-property checks without jQuery, use Object.keys(obj).length === 0 on plain objects.

100% Browser support
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
$.isEmptyObject() Browsers

Bottom line: Use $.isEmptyObject(obj) on plain objects in jQuery apps. Prefer Object.keys when you only need own properties.

Performance Notes

ApproachCostBest for
$.isEmptyObject(obj)O(k) keys seenEmpty checks in jQuery code
Object.keys(obj).length === 0O(n) own keysOwn-property emptiness
Skip check + always extendExtra workTiny option objects (usually fine)

Option objects are usually tiny. Prefer clear guards over micro-optimizing emptiness checks.

Key Takeaways

  • Role: $.isEmptyObject(obj) → no enumerable keys.
  • Input: plain objects only — pair with isPlainObject.
  • Official: {} true · { foo: "bar" } false.
  • Own keys: prefer Object.keys when that is all you need.

One line: use $.isEmptyObject on plain objects to detect “no settings” — confirm plain first, and normalize null/undefined.

Frequently Asked Questions

jQuery.isEmptyObject(object) returns true when the object has no enumerable properties (as seen by for...in). An empty literal {} returns true; { foo: "bar" } returns false.
Yes. The official docs say the argument should always be a plain JavaScript Object. DOM nodes, primitives, and host objects may give inconsistent results across browsers. Confirm with $.isPlainObject() when unsure.
Object.keys counts only own enumerable properties. Since jQuery 1.4, isEmptyObject uses for...in and can also see inherited enumerable properties on the prototype. For typical {} literals both usually agree.
The method expects an object. Passing null or undefined can throw when the internal loop runs. Guard first, or normalize with options || {}.
It is meant for plain objects, not arrays. Use $.isArray() / Array.isArray() and .length for arrays.
A common pattern: if user options are empty, keep defaults; otherwise merge with $.extend({}, defaults, userOptions).
Yes, if jQuery is loaded. It is a data utility and does not need a DOM. Many Node apps prefer Object.keys(obj).length === 0 for own-property checks.

Next: isFunction()

Learn how jQuery tests whether a value is a callable function.

isFunction 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.

8 people found this page helpful