Lodash _.toUpper() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
String

Definition

Converts a string, as a whole, to uppercase — same idea as String#toUpperCase. Separators stay put; only letters change case. Part of Lodash String (stable since 4.0.0 — not deprecated).

Pass the string and options shown below. Check the return type before you chain another helper.

Syntax

Call _.toUpper. Start with this line.

Lodash
_.toUpper([string=''])
CallWhat it does
_.toUpper([string=''])Primary signature.
_.toUpper(string)Transform or inspect a string.

Prefer import toUpper from "lodash/toUpper" when you want a smaller bundle.

Library declarations
Lodash
_.toUpper([string=''])

Parameters

ParameterDescription
stringOptional. Value to convert (default ''; non-strings are coerced)

Return Value

Return ValueDescription
*New uppercased string

Lodash Examples

Example 1 — Official: Hyphenated String

Uppercase letters; keep the dashes.

Lodash
console.log(_.toUpper("--foo-bar--"));
// '--FOO-BAR--'
Try It Yourself

How It Works

  1. Input. Lowercase text with hyphens.
  2. Convert. Each letter becomes uppercase.
  3. Keep. - characters stay in place.
  4. Docs. Matches the official first example.

Example 2 — Official: camelCase Collapses Visually

Case goes away — word boundaries from capitals disappear.

Lodash
console.log(_.toUpper("fooBar"));
// 'FOOBAR'
Try It Yourself

How It Works

  1. Input. fooBar uses a capital for the second word.
  2. Upper. Every letter becomes uppercase.
  3. Result. One flat word: FOOBAR.
  4. Tip. Prefer _.upperCase if you need spaced words.

Example 3 — Official: Underscored Text

Underscores stay; letters rise to uppercase.

Lodash
console.log(_.toUpper("__foo_bar__"));
// '__FOO_BAR__'
Try It Yourself

How It Works

  1. Input. Lowercase identifier-style string.
  2. Convert. foo / bar become uppercase.
  3. Keep. Underscores are unchanged.
  4. Docs. Matches the official third example.

Example 4 — Format a Display Label

Normalize mixed input before showing a badge or code.

Lodash
var status = "active";

console.log("STATUS: " + _.toUpper(status));
// 'STATUS: ACTIVE'
Try It Yourself

How It Works

  1. Input. A lowercase status value.
  2. Upper. _.toUpper makes it display-ready.
  3. Use. Common for labels, SKUs, and short codes.
  4. Note. For title-style text, try _.startCase.

Example 5 — Pair with _.toLower

Same input, opposite case helpers.

Lodash
var s = "Foo-Bar";

console.log(_.toUpper(s)); // 'FOO-BAR'
console.log(_.toLower(s)); // 'foo-bar'
Try It Yourself

How It Works

  1. toUpper. All letters become uppercase.
  2. toLower. All letters become lowercase.
  3. Shared. Both keep the hyphen.
  4. Next. See the _.toLower tutorial.

Browser & Runtime Support

_.toUpper is a Lodash String helper available since 4.0.0. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.x

_.toUpper()

Available in [email protected] full builds and the lodash/toUpper modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.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
_.toUpper Since 4.0.0

Bottom line: Safe for production once Lodash is on the page. Prefer import toUpper from "lodash/toUpper" for smaller builds. Native String#toUpperCase is fine when you do not need Lodash.

Frequently Asked Questions

_.toUpper([string='']) converts the whole string to uppercase, like String#toUpperCase. Official: _.toUpper('--foo-bar--') → '--FOO-BAR--'.
_.toUpper only changes letter case and keeps separators. _.upperCase splits into space-separated uppercase words (e.g. '--foo-bar--' → 'FOO BAR').
For plain strings they usually match. Lodash coerces non-strings first and fits the rest of the Lodash string API.
No. Strings are immutable. _.toUpper always returns a new string.
Use _.toLower for lowercase normalization, slugs, or case-insensitive storage. Use _.toUpper for labels, codes, and display caps.
Use import toUpper from "lodash/toUpper" or require("lodash/toUpper"). Full build: import _ from "lodash" then _.toUpper.

Next: _.trim()

Remove leading and trailing characters from a string.

_.trim() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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