Lodash _.toUpper() 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 _.toUpper() confidently in real string workflows.

01

Core Syntax

Call _.toUpper(string); defaults to empty string.

02

Non-Mutating

Returns a new uppercase string every time.

03

Format Output

Create labels, headings, and status codes.

04

Input Validation

Check typeof before converting user data.

05

Unicode Notes

Some characters have no uppercase form.

06

Production Tips

Know when native toUpperCase() suffices.

What Is _.toUpper()?

_.toUpper() converts every character in the input string to uppercase. It mirrors _.toLower() and is handy when you want shouting-case labels, coupon codes, or consistent display formatting inside a Lodash-heavy codebase.

💡
Beginner tip

Think of _.toUpper(status) as “show this value in all caps for display or comparison.” The source string keeps its original casing.

📝 Syntax

javascript
_.toUpper([string=''])

Syntax Rules

  • string — Optional. Defaults to '' when omitted.
  • Return value — A new string with all uppercase-mappable characters converted.
  • Immutable — Original string is never modified.
  • Coercion — Non-strings are converted with String() first.
javascript
import toUpper from "lodash/toUpper";

const label = "hello, world!";
const result = toUpper(label);
// -> "HELLO, WORLD!"

⚡ Quick Reference

TaskCode patternResult
Basic conversion_.toUpper("hello")"HELLO"
Default arg_.toUpper()""
Format label_.toUpper(name)Display text
Chain trim_.toUpper(_.trim(s))Clean + uppercase
Native altstr.toUpperCase()Built-in equivalent
Opposite_.toLower(str)Lowercase output
Mutates?
No

Returns new string

Default
''

Empty when omitted

Pair with
_.toLower()

Opposite casing

Native
toUpperCase()

Built-in equivalent

🧰 Parameters

string Optional

Value to convert. Defaults to empty string. Coerced to string when provided.

_.toUpper(code)
return value New string

Uppercase copy of the input.

const LABEL = _.toUpper(text)
coercion Automatic

Numbers and other types stringify before uppercasing.

_.toUpper(42) // "42"
Unicode Important

Characters without uppercase mappings stay as-is.

// こんにちは unchanged

Examples Gallery

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

📚 Getting Started

Convert a simple greeting to uppercase.

Example 1 — Basic uppercase conversion

Turn hello, world! into all caps.

javascript
const text = "hello, world!";
const upper = _.toUpper(text);

console.log(upper);
// -> "HELLO, WORLD!"

console.log(text);
// still "hello, world!"
Try It Yourself

How It Works

_.toUpper() returns a new string; the original variable is unchanged.

📈 Practical Patterns

Validate input and format data for display.

Example 2 — Validate then uppercase

Only convert when the input is actually a string.

javascript
function formatLabel(input) {
  if (typeof input !== "string") return "";
  return _.toUpper(_.trim(input));
}

console.log(formatLabel("  draft  "));
// -> "DRAFT"
Try It Yourself

How It Works

Guard against non-string input, trim whitespace, then uppercase for consistent labels.

Example 3 — Chain with _.trim()

Clean messy input before uppercasing for a status banner.

javascript
const messy = "   active   ";
const banner = _.toUpper(_.trim(messy));

console.log(banner);
// -> "ACTIVE"
Try It Yourself

How It Works

Trim first so stray spaces do not appear in the final uppercase string.

Example 4 — Normalize coupon codes

Uppercase user-entered promo codes for lookup tables.

javascript
const entered = "save20";
const code = _.toUpper(entered);
// -> "SAVE20"

How It Works

Store and compare codes in a single casing convention.

Example 5 — Batch format headings

Map section titles to uppercase labels.

javascript
const sections = ["intro", "setup", "deploy"];
const labels = sections.map(_.toUpper);
// -> ["INTRO", "SETUP", "DEPLOY"]

How It Works

Reference _.toUpper directly in map for concise transforms.

🚀 Beyond the Basics

Native alternatives and Unicode caveats.

Example 6 — Native toUpperCase() alternative

Built-in uppercase when Lodash is not in the bundle.

javascript
const text = "hello";
const native = text.toUpperCase();
const lodash = _.toUpper(text);
// both -> "HELLO"

How It Works

Native toUpperCase() is fine for one-off transforms. Keep _.toUpper when chaining with other Lodash helpers.

📋 Related string operations

Topic_.toUpper_.toLowertoUpperCase()_.trim()
PurposeUppercase charsLowercase charsNative uppercaseStrip edge whitespace
Default argEmpty stringNoneN/ANone
MutatesNoNoNoNo
Best forLabels & codesNormalize storageSimple one-offSanitize input

🧠 How _.toUpper() Works

1

Coerce input

Value becomes a string (default "" when omitted).

Input
2

Map characters

Each character is uppercased where a mapping exists.

Transform
3

Join result

Characters form a new string value.

Build
=

Return copy

Original input unchanged; uppercase string returned.

Done

📝 Notes

  • _.toUpper() is non-mutating.
  • Omitting the argument returns "".
  • Non-string values are coerced before conversion.
  • Some Unicode characters have no uppercase form and stay unchanged.
  • Chain with _.trim() to remove surrounding whitespace first.
  • Opposite helper: _.toLower().

Conclusion

_.toUpper() gives you predictable uppercase strings inside the Lodash ecosystem. Use it for display formatting, code normalization, and pipelines that already import Lodash string helpers.

💡 Best Practices

✅ Do

  • Assign the return value—strings are immutable
  • Combine with related helpers when building normalization pipelines
  • Validate user input types before transforming
  • Test Unicode and locale-sensitive strings when relevant
  • Use native string.toUpperCase() when Lodash is not already imported

❌ Don’t

  • Expect the original string variable to change in place
  • Assume behavior matches locale-aware toLocaleLowerCase without testing
  • Trim or change casing before checking for empty input when order matters
  • Import all of Lodash for a single call if tree-shaking a tiny bundle
  • Forget to handle null/undefined coercion edge cases

Key Takeaways

01

New string

Immutable uppercase copy.

Basics
02

Default ''

Safe when arg omitted.

API
03

Format

Labels and promo codes.

Pattern
04

Validate

Check typeof first.

Safety
05

toLower

Opposite casing helper.

Next step

❓ Frequently Asked Questions

_.toUpper() converts every character in a string to uppercase and returns the new string. The original is not modified.
If you omit the string argument, Lodash treats it as an empty string and returns "".
No. Strings are immutable; _.toUpper() always returns a new value.
For plain strings the results match in most cases. Lodash coerces non-strings and fits a consistent utility API.
Characters without an uppercase mapping (many symbols and some scripts) are returned unchanged.
Use _.toLower() when you need lowercase output—for normalization, slugs, or case-insensitive storage.
Did you know?

_.toUpper accepts an optional string and defaults to empty string. Pair it with _.trim() for clean input, or use _.toLower() for the opposite transform.

Practice _.toUpper() in the Live Editor

Open Try It, run the examples, and experiment 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