Underscore.js Utility Methods

Beginner
6 min read
Updated: Nov 2026
15 method guides
Method index

About This Index

This page is the Underscore.js Utility index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.

Learn objects and collections on /underscore-js/object and /underscore-js/collection. Use this page when you need everyday glue such as _.identity(), _.times(), or _.template().

Beginner path.

Start with _.identity(), then _.times(), _.escape(), and _.template()—then browse the rest by category.

How to Call a Utility Method

Call utilities on _ like any other Underscore helper:

Underscore
_.identity(5);           // 5
_.constant("ok")();      // "ok"
_.noop();                // undefined

_.times(3, function (i) { return i * 2; }); // [0, 2, 4]
_.random(1, 6);          // e.g. 4
_.uniqueId("user_");     // "user_1"

_.escape("<div>");       // "&lt;div&gt;"
const greet = _.template("Hello <%= name %>!");
greet({ name: "moe" });  // "Hello moe!"

_.VERSION;               // e.g. "1.13.7"

Underscore.js Utility Methods Table

All utility method guides in this Underscore.js tutorial series (15 tutorials).

Getting Started

4 methods

Reclaim _, identity defaults, constants, and no-op callbacks.

MethodDescriptionTutorial
_.noConflict()Gives the global _ variable back to its previous owner and returns Underscore.Try it
_.identity()Returns the same value that was passed in — the default iteratee.Try it
_.constant()Creates a function that always returns the same value.Try it
_.noop()A function that does nothing — useful as a default callback.Try it

Generate

3 methods

Repeat work, pick random integers, and mint unique ids.

MethodDescriptionTutorial
_.times()Invokes the iteratee n times and returns an array of results.Try it
_.random()Returns a random integer between min and max, inclusive.Try it
_.uniqueId()Generates a globally unique id, optionally with a prefix.Try it

Extend Underscore

2 methods

Add custom methods and normalize iteratees.

MethodDescriptionTutorial
_.mixin()Adds your own functions to Underscore and the OOP wrapper.Try it
_.iteratee()Generates a callback from a function, property name, or matcher object.Try it

Strings & Values

4 methods

Escape HTML, resolve properties, and read the current time.

MethodDescriptionTutorial
_.escape()Escapes HTML special characters for safe insertion into markup.Try it
_.unescape()The inverse of _.escape — turns HTML entities back into characters.Try it
_.result()Reads a property; if it is a function, calls it with the object as this.Try it
_.now()Returns an integer timestamp for the current time.Try it

Template & Version

2 methods

Compile HTML templates and read the loaded library version.

MethodDescriptionTutorial
_.template()Compiles a JavaScript template into a render function.Try it
_.VERSIONThe current Underscore version string (property, not a function).Try it

Frequently Asked Questions

They are general-purpose helpers: identity defaults (_.identity, _.constant, _.noop), generators (_.times, _.random, _.uniqueId), HTML escaping (_.escape, _.unescape), templates (_.template), and library glue (_.noConflict, _.mixin, _.iteratee, _.VERSION).
Most do not. _.identity, _.times, _.escape, and _.uniqueId return new values. _.mixin adds functions onto Underscore itself. _.noConflict only changes the global _ name.
_.identity(value) returns that same value. _.constant(value) returns a function that always returns that value, even if you call it later with other arguments.
Use _.escape to HTML-escape a string yourself. Use _.template to compile a trusted markup string that interpolates data. Underscore HTML-escapes interpolate values by default.
Start with _.identity(), then _.times(), _.escape(), and _.template() from the table below.

Start with _.identity()

Open the identity guide—syntax, examples, and FAQs.

_.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.

12 people found this page helpful