Lodash _.upperCase() Method

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
String utilities

What You’ll Learn

By the end of this tutorial, you’ll use Lodash’s _.upperCase() confidently in real JavaScript projects.

01

Core Syntax

Call _.upperCase(string).

02

Word-aware

Splits compound identifiers into words.

03

vs toUpperCase

Not the same as native all-caps.

04

Labels

Normalize display headings.

05

Search keys

Standardize mixed-case input.

06

Non-mutating

Returns a new string.

What Is _.upperCase()?

_.upperCase() converts a string into uppercase words separated by spaces, using lodash word-segmentation rules. Unlike toUpperCase(), it splits compound identifiers like fooBar into FOO BAR—useful for labels, headings, and normalized search keys.

💡
Beginner tip

Think of _.upperCase('fooBar') as “turn this identifier into a loud, space-separated label”—not the same as 'fooBar'.toUpperCase().

📝 Syntax

javascript
_.upperCase([string=''])
javascript
import upperCase from "lodash/upperCase";

const label = upperCase("userProfileId");
// -> "USER PROFILE ID"

⚡ Quick Reference

TaskCode patternResult
Basic_.upperCase('hello')HELLO
camelCase_.upperCase('fooBar')FOO BAR
kebab-case_.upperCase('foo-bar')FOO BAR
Empty_.upperCase('')''
vs toUpper_.toUpper()Alias-style
Importimport upperCase from 'lodash/upperCase'Per-method
Mutates?
No

Returns new string

vs native
toUpperCase()

Different rules

Output
SPACE SEP

Word split

Related
lowerCase

Inverse helper

🧰 Parameters

stringOptional

Input to convert (default ''). Coerced to string.

return valueNew string

Uppercase words separated by spaces.

word rulesLodash

Splits compound identifiers before uppercasing.

related_.lowerCase()

Inverse case conversion with same word rules.

Examples Gallery

Practical _.upperCase() patterns with copy-ready code and interactive Try It Yourself labs.

📚 Getting Started

Core patterns for _.upperCase() with copy-ready code.

Example 1 — Basic upper case conversion

Convert hello world to space-separated uppercase words.

javascript
const original = "hello world";
console.log(_.upperCase(original));
// -> "HELLO WORLD"
Try It Yourself

How It Works

Run the Try It editor to experiment with _.upperCase() on your own strings.

Example 2 — Compound identifiers

Lodash splits camelCase and kebab-case into words before uppercasing.

javascript
console.log(_.upperCase("fooBar"));
console.log(_.upperCase("foo-bar"));
// -> "FOO BAR" for both
Try It Yourself

How It Works

Run the Try It editor to experiment with _.upperCase() on your own strings.

Example 3 — Empty string handling

An empty input returns an empty string without errors.

javascript
console.log(_.upperCase(""));
// -> ""
Try It Yourself

How It Works

Run the Try It editor to experiment with _.upperCase() on your own strings.

📈 Practical Patterns

Real-world formatting and data-handling scenarios.

Example 4 — Format display labels

Turn internal field keys into readable uppercase labels.

javascript
const field = "dateOfBirth";
const label = _.upperCase(field);
console.log(label);

Example 5 — Compare with toUpperCase()

Native toUpperCase does not insert spaces between camelCase segments.

javascript
const id = "userProfileId";
console.log("upperCase:", _.upperCase(id));
console.log("toUpperCase:", id.toUpperCase());

Example 6 — Normalize search keys

Standardize mixed input before indexing or comparison.

javascript
const input = "  Mixed-Case Value ";
const key = _.upperCase(input.trim());
console.log(key);

🧠 How _.upperCase() Works

1

Receive string

Coerce input (default empty string).

Input
2

Segment words

Apply lodash word boundary rules.

Split
3

Uppercase each

Convert each word segment to uppercase.

Transform
4

Join with spaces

Return space-separated uppercase words.

Output

📝 Notes

  • _.upperCase() is not identical to String.prototype.toUpperCase().
  • Compound strings like fooBar become FOO BAR, not FOOBAR.
  • Empty input returns '' without error.
  • For single-word all-caps, _.toUpper() may be closer to native behavior.
  • Inverse helper: _.lowerCase().
  • Next: _.upperFirst() for first-character capitalization.

Conclusion

_.upperCase() is your go-to for word-aware ALL CAPS labels from mixed-case or compound identifiers. Remember it differs from native toUpperCase() when strings contain camelCase or separators.

💡 Best Practices

✅ Do

  • Use upperCase for identifier-to-label conversion
  • Compare output with toUpperCase when migrating legacy code
  • Handle empty strings explicitly in forms
  • Pair with trim before normalizing search keys
  • Import lodash/upperCase for tree-shaking

❌ Don’t

  • Use upperCase when you only need per-character caps
  • Assume upperCase matches toUpperCase for all inputs
  • Mutate a variable expecting in-place change
  • Use for password or case-sensitive secrets
  • Confuse upperCase with upperFirst

Key Takeaways

📄02

vs toUpperCase

Different rules

Compare
📄03

Labels

Identifiers → display

Use case
📄04

Non-mutating

New string

Basics
📄05

upperFirst

Next method

Nav

❓ Frequently Asked Questions

_.upperCase() converts a string to uppercase words separated by spaces, following lodash case rules—for example 'fooBar' becomes 'FOO BAR'.
String.prototype.toUpperCase() uppercases every character in place. _.upperCase() splits compound identifiers into words and joins them with spaces in uppercase.
_.toUpper() is an alias-style helper closer to native toUpperCase(). _.upperCase() applies lodash word segmentation rules for multi-part strings.
No. It returns a new string. The original is unchanged.
_.upperCase('') returns ''.
For normalizing labels, generating display headings from identifiers, or standardizing search keys derived from mixed-case input.
Did you know?

_.upperCase('fooBar') yields FOO BAR while 'fooBar'.toUpperCase() yields FOOBAR—they solve different problems. See also _.toUpper().

Practice _.upperCase() in the Live Editor

Open the Try It editor and run the examples with your own strings.

Open Try It editor →

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