Lodash _.noConflict() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Util

Definition

Reverts the global _ variable to its previous value and returns a reference to the Lodash function. Part of Lodash Util (stable — not deprecated).

Pass the arguments shown below. Prefer modular imports when you only need this helper.

Syntax

Call _.noConflict. Start with this line.

Lodash
_.noConflict()
CallWhat it does
_.noConflict()Primary signature.
_.noConflict(...)Call the util helper.

Prefer import noConflict from "lodash/noConflict" when you want a smaller bundle.

Library declarations
Lodash
_.noConflict()

Parameters

This method has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*The Lodash function

Lodash Examples

Example 1 — Official: Capture Lodash

Assign the return value, then call Lodash methods on that variable.

Lodash
var lodash = _.noConflict();

lodash.map([1, 2, 3], function (n) {
  return n * 2;
});
// → [2, 4, 6]
Try It Yourself

How It Works

  1. Call once. _.noConflict() returns the Lodash function.
  2. Save it. Store the result in lodash.
  3. Use it. lodash.map doubles each number → [2, 4, 6].
  4. Global. _ is no longer Lodash — do not call _ for Lodash APIs.

Example 2 — Restore a Legacy _

When another library owned _ first, noConflict gives it back.

Lodash
// pretend a legacy lib already set window._
window._ = {
  library: 'legacy',
  greet: function () { return 'from legacy'; }
};

// then Lodash loads and overwrites _
// (in the Try It lab, Lodash loads after the stub)

var lodash = _.noConflict();

_.greet();           // → 'from legacy'
lodash.sum([1, 2, 3]); // → 6
Try It Yourself

How It Works

  1. Before. A stub “legacy” object owns global _.
  2. Load. Lodash takes over _ when its script runs.
  3. Restore. noConflict puts the legacy object back on _.
  4. Both work. _.greet() is legacy; lodash.sum is Lodash.

Example 3 — Custom Variable Name

Any clear name works — not only lodash.

Lodash
var _lodash = _.noConflict();

_lodash.map([1, 2, 3], function (n) {
  return n * 2;
});
// → [2, 4, 6]
Try It Yourself

How It Works

  1. Rename. Store the return value as _lodash.
  2. Same API. All Lodash methods hang off that variable.
  3. Clarity. Names like lodash or _lodash signal intent.
  4. Global. _ is free for other libraries again.

Example 4 — noConflict vs runInContext

Different goals: free the name vs clone Lodash.

Lodash
// noConflict — free global _, keep one Lodash reference
var lodash = _.noConflict();
// window._ restored; use `lodash`

// runInContext — extra Lodash copy; global _ unchanged
var isolated = lodash.runInContext();
isolated.mixin({ double: function (n) { return n * 2; } });
isolated.double(21);
// → 42
Try It Yourself

How It Works

  1. noConflict. Gives up global _; you keep one Lodash handle.
  2. runInContext. Builds a private Lodash without restoring _.
  3. Mixins. Extend the isolated copy so the shared API stays clean.
  4. Pick. Name clash → noConflict; plugin isolation → runInContext.

Browser & Runtime Support

_.noConflict is a Lodash Util helper (stable). It is meaningful mainly in browsers with a global _. In Node / Bun / Deno, prefer require or import — no global clash to resolve.

✓ Stable · Script-tag utility

_.noConflict()

Available in [email protected] full builds loaded via CDN or script tag. Modular imports already avoid window._ conflicts.

100% With full Lodash build
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.noConflict Full Lodash build

Bottom line: Use in browser pages that share global _. Prefer import/require in modern apps. Always assign the return value once.

Frequently Asked Questions

_.noConflict() restores the global _ variable to whatever it was before Lodash loaded, and returns the Lodash function. Capture it: var lodash = _.noConflict(); then call lodash.map(...).
No. Call it once and assign the return value. After the first call, global _ is no longer Lodash, so a second call can fail or return the wrong thing.
Mostly with browser script tags when another library (often Underscore) also uses _. With npm or ES module imports, each file has its own binding — noConflict is rarely needed.
No. It only frees the global _ name. Lodash still works through the variable you saved from the return value.
noConflict restores the previous global _. runInContext creates a separate Lodash copy without giving up the global — better for plugins and isolated mixins.
No. It is a stable Lodash Util method. Prefer module imports in modern apps; use noConflict for script-tag name clashes.

Next: _.noop()

Use Lodash’s empty function as a safe default callback.

_.noop() 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.

10 people found this page helpful