Underscore.js _.unescape() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Utility

Definition

The inverse of _.escape — replaces &, <, >, ", ', and ` with their unescaped counterparts (official Underscore docs). Stable since 1.4.0 — not deprecated.

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

Syntax

Call _.unescape. Start with this line.

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

Parameters

ParameterDescription
stringRequired. Text that may contain escape entities

Return Value

Return ValueDescription
*New string with the six entities restored

Underscore.js Examples

Example 1 — Official Docs Example

Restore the ampersand in the Stooges names string.

Underscore
_.unescape("Curly, Larry & Moe");
// → "Curly, Larry & Moe"
Try It Yourself

How It Works

  1. Input. The string contains the entity &.
  2. Replace. Underscore maps that entity back to &.
  3. Result. "Curly, Larry & Moe" — official docs sample.
  4. Pair. This reverses the official _.escape example.

Example 2 — All Six Entities

Only the entities that _.escape produces are restored.

Underscore
_.unescape("&<>"'`");
// → "&<>\"'`"
Try It Yourself

How It Works

  1. Map. Six entities → & < > " ' `.
  2. Order. Same characters _.escape encodes.
  3. Apostrophe. Underscore uses &#x27;, not &apos;.
  4. Scope. Not a full HTML5 entity decoder.

Example 3 — Escape Round-Trip

unescape(escape(s)) restores the original for the six sensitive characters.

Underscore
var original = "Curly, Larry & Moe";
var encoded = _.escape(original);

_.unescape(encoded);
// → "Curly, Larry & Moe"

_.unescape(encoded) === original;
// → true
Try It Yourself

How It Works

  1. Escape. & becomes &amp;.
  2. Unescape. That entity becomes & again.
  3. Equality. Round-trip matches the original string.
  4. Limit. Only works for Underscore’s six-entity set.

Example 4 — Unknown Entities Stay Put

&nbsp;, &copy;, and &apos; are not in the map.

Underscore
_.unescape("&nbsp;");   // → "&nbsp;"
_.unescape("&copy;");   // → "&copy;"
_.unescape("&apos;");   // → "&apos;"
_.unescape("&#x27;");   // → "'"
Try It Yourself

How It Works

  1. Unknown. Entities outside the six-entity map are left alone.
  2. nbsp / copy. Still the entity text after unescape.
  3. apos. Underscore does not treat &apos; as a quote.
  4. '. That is the apostrophe form Underscore knows.

Example 5 — One Layer & Nullish Input

One replace pass. null / undefined become an empty string.

Underscore
_.unescape("&amp;amp;");
// → "&amp;"

_.unescape(_.unescape("&amp;amp;"));
// → "&"

_.unescape(null);       // → ""
_.unescape(undefined);  // → ""
Try It Yourself

How It Works

  1. One layer. &amp;amp; becomes &amp;, not &.
  2. Second call. Needed only if the string was escaped twice.
  3. Nullish. Missing values coerce to "".
  4. Safe default. You do not get "null" as text.

Browser & Runtime Support

_.unescape ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.unescape()

Available in [email protected] (UMD / ESM). Added in 1.4.0 as the inverse of _.escape. Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.x
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
_.unescape Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.unescape(string) is the opposite of _.escape. It replaces the HTML entities &amp;, &lt;, &gt;, &quot;, &#x27;, and &#x60; with &, <, >, ", ', and `.
_.unescape('Curly, Larry &amp; Moe') returns 'Curly, Larry & Moe'. That is the reverse of the official _.escape example.
No. Only the six entities that _.escape produces. &nbsp;, &copy;, &apos;, and most numeric entities are left unchanged.
Yes for the six HTML-sensitive characters Underscore encodes. It is not a full HTML5 decoder, so text that used other entities will not round-trip.
No. Unescape restores < and & so the browser can treat the string as markup. Prefer textContent, or escape on output. Unescape is for recovering original text, not for rendering HTML.
No. It is a stable Underscore utility added in version 1.4.0 so you can reverse _.escape without a second library.

Next: _.result()

Resolve a property that may be a raw value or a function that returns one.

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

11 people found this page helpful