By the end of this tutorial, you’ll capitalize the first letter of any string while keeping the rest unchanged using Lodash’s _.capitalize().
01
Core Syntax
Call _.capitalize(string) with any text value.
02
First Letter Only
Only index 0 changes; the remainder stays as-is.
03
UI Labels
Polish headings, names, and dynamic messages for display.
04
vs upperFirst
Understand when _.upperFirst is equivalent.
05
Input Validation
Handle empty strings and non-string edge cases safely.
06
Production Tips
Do not confuse with title case or full uppercasing.
Fundamentals
What Is _.capitalize()?
_.capitalize() uppercases the first character of a string and leaves every other character exactly as it was. It does not lowercase the rest of the string or capitalize each word—that is the job of _.startCase().
💡
Beginner tip
Think of _.capitalize('hello, world!') as “make the first letter uppercase for display,” not “fix the entire sentence.”
Use it for greeting messages, form field previews, toast notifications, and anywhere you want a quick polish without restructuring the whole string.
Foundation
📝 Syntax
Pass the string whose first character should be uppercased:
javascript
_.capitalize(string)
Syntax Rules
string — the input text. Coerced to string if needed.
First char only — characters at index 1 and beyond are untouched.
Return value — a new string with the first character uppercased.
Empty string — returns an empty string without error.
Not title case — internal words are not capitalized.
javascript
import capitalize from "lodash/capitalize";
const original = "hello, world!";
const result = capitalize(original);
// -> "Hello, world!"
Cheat Sheet
⚡ Quick Reference
Task
Code pattern
Result
Basic capitalize
_.capitalize('hello')
Hello
Preserve rest
_.capitalize('iPhone rules')
IPhone rules
Empty input
_.capitalize('')
''
First char only
_.upperFirst(str)
Same as capitalize for strings
Title every word
_.startCase(str)
Foo Bar style
All uppercase
_.toUpper(str)
ENTIRE STRING
Mutates?
No
Returns a new string
Scope
Index 0
First character only
Similar
_.upperFirst()
Equivalent behavior
Not this
_.startCase()
Capitalizes each word
Reference
🧰 Parameters
Arguments to _.capitalize() and what they control:
stringRequired
The string to capitalize. Non-string values are coerced with String().
_.capitalize('hello')
return valueNew string
A copy with the first character uppercased. The original string is unchanged.
// -> 'Hello'
rest unchangedImportant
Characters after index 0 keep their original casing and punctuation.
_.capitalize('hello WORLD')
empty inputEdge case
An empty string returns '' without throwing.
_.capitalize('')
For capitalizing every word in a phrase, use _.startCase(). For identifier-style names, use _.camelCase().
Hands-On
Examples Gallery
Practical _.capitalize() patterns with copy-ready code, sample output, and interactive Try It Yourself labs.
📚 Getting Started
Capitalize the first letter while preserving the rest of the string.
Example 1 — Capitalize a greeting
Uppercase the first character of a casual greeting string.
javascript
import capitalize from "lodash/capitalize";
const original = "hello, world!";
const capitalized = capitalize(original);
console.log(capitalized);
// -> "Hello, world!"
capitalize touches one character; startCase restructures words; toUpper uppercases everything.
Compare
📋 _.capitalize vs related operations
Topic
_.capitalize
_.upperFirst
_.startCase
_.toUpper
Characters changed
First only
First only
Each word
All
Rest of string
Unchanged
Unchanged
Reformatted
Uppercased
Typical use
Quick polish
Alias of capitalize
Titles
Shout text
Example output
Hello world
Hello world
Hello World
HELLO WORLD
Mutates input
No
No
No
No
🧠 How _.capitalize() Works
1
Coerce to string
Lodash converts the input to a string if needed.
Input
2
Read first character
The character at index 0 is isolated for transformation.
Parse
3
Uppercase first char
That single character is converted to uppercase.
Transform
4
Concatenate remainder
The rest of the string (index 1+) is appended unchanged.
Join
=
📝
Capitalized string returned
A display-ready string with only the first letter uppercased.
Important
📝 Notes
_.capitalize() is equivalent to _.upperFirst() for strings.
It does not lowercase the remaining characters.
It does not capitalize each word—use _.startCase() for that.
Empty strings return '' without throwing.
Validate user input type before calling if your app expects strict strings.
Import lodash/capitalize for minimal bundle size.
Wrap Up
Conclusion
_.capitalize() is a small but handy helper for polishing text in UI copy, notifications, and dynamic messages. One call, one character changed, zero surprises for the rest of the string.
When you need every word capitalized, switch to _.startCase(). For identifier-style names, use _.camelCase() instead.
Document when you need title case vs single capitalize
❌ Don’t
Expect title-case formatting from capitalize
Use for proper-noun localization (locale rules differ)
Lowercase the rest manually unless that is intentional
Confuse with _.camelCase for identifier conversion
Assume it fixes underscore-separated names into titles
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.capitalize()
Use these points whenever you need a quick first-letter uppercase.
5
Core concepts
📝01
One char
Only index 0 changes.
Basics
🖼02
UI polish
Great for labels and toasts.
Pattern
🔄03
upperFirst
Functionally equivalent alias.
Related
⚠04
Not title case
Use startCase for words.
Caveat
⚡05
Tree-shake
Import lodash/capitalize.
Bundle
❓ Frequently Asked Questions
_.capitalize() uppercases the first character of a string and leaves all other characters unchanged.
No. Only the first character is modified. The remainder keeps its original casing.
_.startCase() capitalizes each word and inserts spaces. _.capitalize() only changes the very first character.
Yes. For strings, _.capitalize() and _.upperFirst() produce the same result in Lodash.
_.capitalize('') returns an empty string without throwing an error.
For display titles with each word capitalized, prefer _.startCase(). capitalize only fixes the first letter of the entire string.
Did you know?
_.capitalize() and _.upperFirst() are aliases in Lodash—same behavior, different name. For multi-word titles like “Jane Smith”, use _.startCase() instead of expecting capitalize to fix every word.