Assigns source properties to the destination for keys that are still undefined. Sources apply left to right; once a property is set, later values for that key are ignored. Since Lodash 0.1.0.
Pass the object and path or keys shown below. Check whether the helper mutates or returns a new object.
Syntax
Call _.defaults. Start with this line.
Lodash
_.defaults(object, ...sources)
Call
What it does
_.defaults(object, ...sources)
Primary signature.
_.defaults(object)
Work with an object’s keys, values, or paths.
Prefer import defaults from "lodash/defaults" when you want a smaller bundle.
Order matters — put higher-priority defaults earlier.
Compatibility
Browser & Runtime Support
_.defaults is a Lodash Object helper (since 0.1.0). It runs anywhere Lodash 4.x runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 0.1.0+
_.defaults()
Available in [email protected] full builds and the lodash/defaults modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 4.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
_.defaultsLodash 0.1.0+
Bottom line: Safe for production once Lodash is loaded. Prefer import defaults from "lodash/defaults". Use defaultsDeep when nested objects need gap-filling too.
Frequently Asked Questions
_.defaults(object, ...sources) assigns source properties to the destination only where the destination value is undefined. Sources apply left to right; once a key is set, later sources are ignored for that key.
_.assign overwrites — later sources win. _.defaults only fills undefined gaps — the destination (and the first defining source) win.
No. Only undefined counts as missing. null is treated as already set.
Yes. Pass {} when you want a fresh object: _.defaults({}, userOpts, factoryDefaults).
No. Nested objects already present on the destination are left alone. Use _.defaultsDeep for recursive gap-filling.
Use import defaults from "lodash/defaults" or require("lodash/defaults"). Full build: import _ from "lodash" then _.defaults.