jQuery.extend(target, object1, …) (alias $.extend) merges properties into the first object and returns it (since jQuery 1.0). Pass true first for a recursive deep merge (since 1.1.4).
Choose a target, decide shallow vs deep, then merge sources left to right.
Pick the target (often {} if you want a fresh object).
Optionally pass true first for a deep merge.
Pass one or more source objects — later keys overwrite earlier ones.
Use the returned object (same reference as the target).
Piece
Required?
Role
deep
No
true for recursive merge (only true supported)
target
Yes*
Receives properties (*omitted when extending jQuery)
object1…N
Yes
Sources to copy from
Return value
—
The modified target object
Pseudocode
Pseudocode
function extend(deep, target, sources...):
for each source in sources:
for each key in source:
if value is undefined: skip
if deep and both values are plain objects/arrays:
merge recursively into target[key]
else:
target[key] = value // replace
return target
Reference
Cheat Sheet
Keep these facts handy when merging config objects.
One argument. Target defaults to the jQuery object.
Add method.greet becomes available as $.greet.
Call it like any other jQuery utility.
Use case. Classic pattern for plugin authors adding helpers.
Edge Cases & Pitfalls
Check these before relying on $.extend in plugins.
mutate
Target is modified
The first object changes in place. Use $.extend({}, …) when you need a copy.
shallow
Nested objects are replaced by default
Without true, a nested source object overwrites the whole nested target value.
types
Date / RegExp / custom classes
They are not reconstructed on deep extend — they may appear as plain objects. Prefer a custom merge or a library for those cases.
false
Do not pass false as deep
Only omit the flag (shallow) or pass true. false is not supported.
Compatibility
Browser Support
jQuery.extend() has shipped since jQuery 1.0 (deep flag since 1.1.4). It works in all modern browsers with jQuery loaded. Prefer jQuery 3.4+ for safer deep merges.
✓ jQuery 1.0+
jQuery.extend()
Supported everywhere jQuery runs in the browser. Use shallow merge by default; pass true for deep.
100%Browser support
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
$.extend()Excellent
Bottom line: Call $.extend(target, src) or $.extend(true, target, src). Use {} as the target to preserve originals.
One line:$.extend(target, src) merges into the target — add true for deep, or start with {} to keep originals.
Frequently Asked Questions
jQuery.extend(target, object1, …) copies properties from one or more sources into target. The target is modified in place and also returned. Null and undefined sources are ignored.
Default is shallow: a nested object on the target is replaced wholesale by the same key from a source. Pass true first — $.extend(true, target, source) — to recursively merge plain objects and arrays.
Use an empty object as the target: var settings = $.extend({}, defaults, options). defaults stays untouched; settings gets the combined result.
No. undefined values are skipped. Inherited prototype properties on sources can still be copied.
Object.assign() is shallow only and native ES2015+. $.extend() also supports deep merge with true and has long been the plugin pattern for defaults + options in jQuery.
If you pass a single object, jQuery itself is the target — properties are added to the $ / jQuery namespace. Plugin authors use this to register helpers like $.myPlugin.