Underscore.js _.isString() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Returns true if object is a String (official Underscore docs). Primitives like "moe", empty strings, and boxed new String() pass; numbers and objects do not. Stable helper — not deprecated.

Pass the required arguments shown below. Underscore object helpers usually return a new value — check whether the source object is mutated.

Syntax

Call _.isString. Start with this line.

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

Parameters

ParameterDescription
objectRequired. Value to test

Return Value

Return ValueDescription
*true or false

Underscore.js Examples

Example 1 — Official: "moe"

The docs check Underscore’s classic sample string.

Underscore
_.isString("moe");
// → true
Try It Yourself

How It Works

  1. Primitive text. "moe" is a string literal.
  2. Tag check. Underscore sees [object String] → true.
  3. Official example. This is the sample from the Underscore documentation.
  4. Read-only. Nothing is mutated; you only get a boolean.

Example 2 — Empty String Still Passes

isString answers type, not whether the text has content.

Underscore
_.isString("");
// → true

_.isEmpty("");
// → true  (separate check for blank / empty)
Try It Yourself

How It Works

  1. Empty literal. "" is still typeof "string".
  2. isString says yes. Type check does not look at length.
  3. Need blank detection? Use _.isEmpty or check .length.
  4. Rule. isString = “is text?”; isEmpty = “has no content?”

Example 3 — Boxed String vs typeof

new String() is an object to typeof, but Underscore still treats it as a string.

Underscore
typeof "moe";                 // → "string"
typeof new String("moe");     // → "object"

_.isString("moe");            // → true
_.isString(new String("moe")); // → true
_.isString(42);               // → false
Try It Yourself

How It Works

  1. Primitive. Normal quotes give typeof "string".
  2. Boxed trap. new String() makes typeof report "object".
  3. Tag wins. Underscore uses [object String], so both forms pass.
  4. Non-strings. Numbers and other types still return false.

Example 4 — Guard Before .trim()

Only call string methods after confirming the value is text.

Underscore
function safeTrim(value) {
  if (!_.isString(value)) {
    return "";
  }
  return value.trim();
}

safeTrim("  moe  ");  // → "moe"
safeTrim(42);         // → ""
safeTrim(null);       // → ""
Try It Yourself

How It Works

  1. Guard first. Skip non-strings so .trim() never throws.
  2. String path. Trim whitespace from real text → "moe".
  3. Fail closed. Numbers and null return an empty string.
  4. Pattern. Type-check → then call string methods.

Browser & Runtime Support

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

_.isString()

Available in [email protected] (UMD / ESM). 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
_.isString 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

_.isString(object) returns true when the value is a String — a primitive such as "moe", an empty string, a template literal, or a boxed new String() object. Numbers, arrays, objects, and null return false.
_.isString("moe") returns true. moe is Underscore’s classic sample string, so the docs use it to show a real String passing the check.
Yes. "" is still a String. isString answers type, not length. Pair it with _.isEmpty if you also need to reject blanks.
typeof "moe" === "string" agrees for primitives. typeof new String("moe") is "object", so typeof misses boxed strings. Underscore’s tag check accepts both forms.
Use it as a guard before calling string methods like split, trim, or toUpperCase, or when an API value might be text, a number, or null.
No. It is a stable Underscore type helper. Load Underscore 1.x (CDN or npm) and call _.isString(value).

Next: _.isNumber()

Learn how to detect Number values — including the NaN quirk.

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