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.
Fundamentals
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.
Foundation
📝 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!"
Cheat Sheet
⚡ Quick Reference
Task
Code pattern
Result
Basic conversion
_.toUpper("hello")
"HELLO"
Default arg
_.toUpper()
""
Format label
_.toUpper(name)
Display text
Chain trim
_.toUpper(_.trim(s))
Clean + uppercase
Native alt
str.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
Reference
🧰 Parameters
stringOptional
Value to convert. Defaults to empty string. Coerced to string when provided.
_.toUpper(code)
return valueNew string
Uppercase copy of the input.
const LABEL = _.toUpper(text)
coercionAutomatic
Numbers and other types stringify before uppercasing.
_.toUpper(42) // "42"
UnicodeImportant
Characters without uppercase mappings stay as-is.
// こんにちは unchanged
Hands-On
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!"
_.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.
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
Summary
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.