Returns object after filling its undefined properties with the first value present in the following list of defaults objects (official Underscore docs). Stable Object helper — not deprecated.
Pass the required arguments shown below. Underscore object helpers usually return a new value — check whether the source object is mutated.
Syntax
Call _.defaults. Start with this line.
Underscore
_.defaults(object, *defaults)
Call
What it does
_.defaults(object, *defaults)
Primary signature.
_.defaults(...)
Call with the arguments your case needs.
Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.
Library declarations
Underscore
_.defaults(object, *defaults)
Parameters
Parameter
Description
object
Required. Target to fill (mutated and returned)
*defaults
Required. One or more source objects of fallback values
Return Value
Return Value
Description
*
Same object reference
Underscore.js Examples
Example 1 — Fill Missing Keys
Official-style fill: set keys win; missing keys take the default.
Fresh target. Start with {} so the caller’s object is untouched.
User wins. Copy options next — columns: 6 is set.
Presets last. Defaults fill only still-undefined keys.
Result. Merged config object, ready to use.
Compatibility
Browser & Runtime Support
_.defaults ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.
✓ Stable · Underscore 1.x
_.defaults()
Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.
100%With Underscore 1.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.defaultsUnderscore 1.x+
Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).
Frequently Asked Questions
_.defaults(object, *defaults) fills undefined properties on object from one or more defaults objects, then returns that same object. Ideal for option fallbacks.
Yes. It mutates and returns the first argument. To keep the caller’s object untouched, use _.defaults({}, options, presets).
Only keys that are undefined (including missing keys). Values like null, false, 0, or '' stay as-is.
They are applied in order; the first present value wins. Later defaults do not override a key already filled.
_.extend overwrites existing keys. _.defaults only fills undefined keys and never clobbers set values.
No. It is a shallow, top-level fill. Nested objects are assigned by reference, not merged recursively.