_.defaultTo is a Lodash Util helper since 4.14.0. It runs anywhere Lodash 4.14+ runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 4.14.0+
_.defaultTo()
Available in [email protected] full builds and the lodash/defaultTo modular import. Works in evergreen browsers and current Node LTS when Lodash ≥ 4.14 is installed.
100%With Lodash 4.14+
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
_.defaultToLodash 4.14.0+
Bottom line: Safe for production once Lodash 4.14+ is loaded. Prefer import defaultTo from "lodash/defaultTo" for smaller bundles. Use it when 0 and empty strings must survive, but NaN should still fall back.
Frequently Asked Questions
_.defaultTo(value, defaultValue) returns value unless value is null, undefined, or NaN — then it returns defaultValue. Official: _.defaultTo(1, 10) → 1; _.defaultTo(undefined, 10) → 10.
No. 0, '', and false are kept. Only null, undefined, and NaN trigger the fallback.
|| replaces every falsy value (0, '', false, null, undefined, NaN). _.defaultTo keeps 0 and '' — safer for counts and text fields.
?? falls back only for null and undefined. _.defaultTo also falls back for NaN. That NaN check is the main Lodash difference.
_.defaultTo works on one value. _.defaults fills missing undefined keys on an object from source objects.
Use import defaultTo from "lodash/defaultTo" or require("lodash/defaultTo"). Full build: import _ from "lodash" then _.defaultTo.