Underscore.js _.noConflict() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Utility

Definition

Gives control of the global _ variable back to its previous owner (official Underscore docs). Returns a reference to the Underscore object so you can keep using it under another name.

Pass the required arguments shown below. Underscore utility helpers usually return a new value or function — check edge cases before you ship.

Syntax

Call _.noConflict. Start with this line.

Underscore
_.noConflict()
CallWhat it does
_.noConflict()Primary signature.
_.noConflict(...)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
_.noConflict()

Parameters

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

Return Value

Return ValueDescription
*The Underscore object

Underscore.js Examples

Example 1 — Official Rename

Capture the return value so Underscore stays reachable under a new name.

Underscore
var underscore = _.noConflict();

underscore.first([10, 20, 30]);
// → 10
Try It Yourself

How It Works

  1. Call noConflict. Underscore gives back the global _ name.
  2. Save the return. underscore still points at Underscore.
  3. Call methods. underscore.first(…) works as before.
  4. Global _. No longer Underscore (previous owner or undefined).

Example 2 — Keep Calling Underscore Helpers

After renaming, use the new variable for map, filter, and friends.

Underscore
var us = _.noConflict();

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

us.identity(42);
// → 42
Try It Yourself

How It Works

  1. Rename once. us holds Underscore.
  2. Map as usual. Same API, different variable name.
  3. Other helpers. us.identity still works.
  4. Nothing removed. Only the global name changed.

Example 3 — Previous Owner Restored

Simulate another library owning _ before Underscore loads, then free the name.

Underscore
// Imagine this ran before Underscore's script:
// window._ = { brand: "other-lib" };

var us = _.noConflict();

// us is Underscore
us.VERSION;           // e.g. "1.13.8"

// global _ is the previous owner again
// (in a clean page with no prior _, typeof _ === "undefined")
Try It Yourself

How It Works

  1. UMD saved the old _. Stored as previousUnderscore at load time.
  2. noConflict restores it. Global name goes back.
  3. You keep Underscore. Via the returned reference.
  4. Conflict solved. Two libraries can coexist without sharing _.

Example 4 — Call Once and Keep the Handle

After the first call, do not use the old global _ to call noConflict again.

Underscore
var us = _.noConflict();   // ✓ once

us.map([1, 2], us.identity);
// → [1, 2]

// _.noConflict();  // ✗ usually throws — _ is not Underscore anymore
Try It Yourself

How It Works

  1. First call. Saves Underscore and frees _.
  2. Use us. All later API calls go through that variable.
  3. Skip a second call. Global _ no longer has noConflict.
  4. Rule. Assign once at startup; never rely on global _ afterward.

Browser & Runtime Support

_.noConflict ships with the UMD / browser script build of Underscore.js. It is omitted from ES module, AMD, and CommonJS builds because those never claim a shared global _.

✓ Stable · UMD / script tag

_.noConflict()

Available when Underscore is loaded as a global (e.g. [email protected] UMD CDN). Not exported in ESM/CJS module entry points.

UMD Script-tag / UMD builds
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 UMD only

Bottom line: Use noConflict only with a script-tag or UMD build. With npm ESM/CJS imports, bind Underscore to a local name instead — there is no global conflict to resolve.

Frequently Asked Questions

_.noConflict() restores the global _ variable to whatever it was before Underscore loaded, then returns the Underscore object. Capture that return value — var underscore = _.noConflict() — so you can keep calling Underscore methods.
var underscore = _.noConflict(); After that line, call underscore.map or underscore.first instead of _.map. Global _ belongs to its previous owner again.
No. It only changes the global _. Underscore still exists on the variable you assigned from the return value.
No. Assign the return value once. After the first call, global _ is no longer Underscore, so a second _.noConflict() typically throws.
The official docs say the helper is not present if you import Underscore with ES6, AMD, or CommonJS. Those loaders never take over a shared global _, so there is nothing to restore. Use the UMD/script-tag build when you need noConflict.
No. It is a stable Underscore utility for browser script-tag setups where another library also wants the _ name.

Next: _.identity()

Learn Underscore’s pass-through function — f(x) = x — used as the default iteratee.

_.identity() tutorial →

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