Lodash _.isString() method

Beginner
⏱️ 5 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.isString(value) accepts both string primitives and boxed String objects.
  • Why this is broader than a bare typeof === "string" check.
  • How empty strings still count as valid strings.
  • Where to combine this guard with a length or pattern check.

Prerequisites

You can tell a string primitive from a boxed wrapper such as new String("hello").

  • You have used template literals and traditional string quotes.
  • Try-it labs load lodash from the CDN.

Overview

Use _.isString before string-only operations—trimming, splitting, regex matching, or template interpolation—so accidental numbers, nulls, or arrays don’t crash your call chain.

Primitive + boxed

Accepts "abc" and new String("abc").

Empty still counts

"" is a string. Use length if you need non-empty.

Cross-realm safe

Tag check survives boundary cases instanceof String misses.

Syntax

javascript
_.isString(value)
  • value: any value to test.
  • Returns: true when value is a String primitive or a boxed String object; otherwise false.
1

String primitives

The lodash docs baseline: literals and template strings always return true.

javascript
import isString from "lodash/isString";

console.log(
  "abc: " + isString("abc") + "\n" +                  // true (lodash docs)
  "template: " + isString(`Hello, world!`) + "\n" +     // true
  "empty: " + isString("")                              // true
);
Try it Yourself
2

Boxed new String() objects

Lodash sees the internal [object String] tag, so wrappers also pass—unlike a bare typeof.

javascript
import isString from "lodash/isString";

const boxed = new String("boxed");

console.log(
  "boxed: " + isString(boxed) + "\n" +              // true
  "typeofRaw: " + (typeof boxed)                     // "object"
);
Try it Yourself
3

Numbers, arrays, and nullish

Other types never qualify—the lodash docs example shows _.isString(1) as false.

javascript
import isString from "lodash/isString";

console.log(
  "num: " + isString(1) + "\n" +              // false (lodash docs)
  "arr: " + isString(["a", "b"]) + "\n" +      // false
  "obj: " + isString({ text: "x" }) + "\n" +    // false
  "nullVal: " + isString(null)                  // false
);
Try it Yourself

📋 _.isString vs related checks

API / patternBehavior
_.isString(x)true for both string primitives and boxed String objects.
typeof x === "string"Primitive only—misses new String(…).
x instanceof StringOnly the boxed object form; misses primitives.
Object.prototype.toString.call(x)Manual tag check—lodash wraps the same idea.

Pitfalls to avoid

Truthy

Empty vs missing

_.isString("") is true—don’t rely on truthiness to detect blank inputs.

Coercion

No auto-conversion

A numeric 42 never passes; call String(value) or template-tag it yourself.

Boxed

Boxed objects break typeof

A wrapped new String("x") is typeof object; _.isString still returns true.

❓ FAQ

Yes—"" is still a valid String primitive. Combine with a length check if your validator also requires non-empty input.
Boxed primitives have typeof object, but their internal [[Class]] tag is "[object String]". Lodash recognizes that and returns true—matching its docs.
Yes. The tag-based branch handles cross-realm String objects where instanceof String can fail.
Template literals evaluate to plain strings, so _.isString(`hi`) returns true.

Summary

  • Purpose: confirm a value is a String primitive or boxed wrapper before string operations.
  • Remember: empty "" still counts; numbers and arrays do not.
  • Next: explore more on Lodash _.isSymbol().
Did you know?

_.isString accepts both "abc" and new String("abc") because lodash checks the internal [object String] tag in addition to typeoftypeof new String("x") alone returns "object".

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.

6 people found this page helpful