jQuery isEmptyObject() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Utilities

Definition

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.

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$.isEmptyObject(object)  → true | false

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

// Official guidance: plain objects only
$.isPlainObject(obj) && $.isEmptyObject(obj)
CallWhat it does
isEmptyObject()Learn jQuery.isEmptyObject(): check if a plain object has no enumerable properties, pair with isPlainObject, compare with Object.keys, defaults with extend, examples, pitfalls, and FAQs.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Start with a plain object (options, config, API payload).
Step 2Optionally confirm with $.isPlainObject(obj).
Step 3Call $.isEmptyObject(obj).

Return Value

Return ValueDescription
BooleanOften true or false depending on the match or state.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

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.

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.

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

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() Method

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

isFunction() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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