Home Lodash String methods _.upperFirst() Lodash _.upperFirst() Method Overview
What You’ll Learn By the end of this tutorial, you’ll use Lodash’s _.upperFirst() confidently in real JavaScript projects.
01
Core Syntax Call _.upperFirst(string).
02
First char only Rest of the string unchanged.
03
vs capitalize Does not lowercase the tail.
04
Headings Format titles and labels.
05
User input Sentence-style capitalization.
06
Non-mutating Returns a new string.
Fundamentals
What Is _.upperFirst()? _.upperFirst() uppercases only the first character of a string and leaves the rest unchanged. Unlike _.capitalize() , it does not lowercase the tail—handy for sentence-style headings and preserving intentional mixed case.
💡
Beginner tip Think of _.upperFirst(title) as “sentence-case the first letter” without rewriting the rest of the string.
Foundation
📝 Syntax _.upperFirst([string='']) import upperFirst from "lodash/upperFirst";
const heading = upperFirst("welcome back");
// -> "Welcome back" Cheat Sheet
⚡ Quick Reference Task Code pattern Result Basic _.upperFirst('hello')Hello Preserve tail _.upperFirst('hELLO')HELLO Empty _.upperFirst('')'' vs capitalize _.capitalize() Also lowercases rest vs startCase _.startCase() Every word Import import upperFirst from 'lodash/upperFirst'Per-method
Mutates? NoReturns new string
Scope 1st charRest unchanged
vs capitalize DifferentNo tail lower
Reference
🧰 Parameters stringOptional
Input string (default ''). Coerced to string.
return valueNew string
First character uppercased; remainder unchanged.
empty input''
Returns empty string without error.
related_.capitalize()
Also lowercases characters after the first.
Hands-On
Examples Gallery Practical _.upperFirst() patterns with copy-ready code and interactive Try It Yourself labs.
Basic Preserve Empty 📚 Getting Started Core patterns for _.upperFirst() with copy-ready code.
Example 1 — Capitalize the first character Turn hello, world! into Hello, world!.
const text = "hello, world!";
console.log(_.upperFirst(text));
// -> "Hello, world!" How It Works Run the Try It editor to experiment with _.upperFirst() on your own strings.
Example 2 — Preserve existing casing Only the first character changes—mixed case in the rest stays as-is.
const mixed = "hELLO, wORLD!";
console.log(_.upperFirst(mixed));
// -> "HELLO, wORLD!" How It Works Run the Try It editor to experiment with _.upperFirst() on your own strings.
Example 3 — Empty string Returns '' for an empty input.
console.log(_.upperFirst(""));
// -> "" How It Works Run the Try It editor to experiment with _.upperFirst() on your own strings.
📈 Practical Patterns Real-world formatting and data-handling scenarios.
Example 4 — Format a page heading Capitalize user or CMS titles for display.
const cmsTitle = "welcome to our website";
console.log(_.upperFirst(cmsTitle)); Example 5 — Compare with _.capitalize() capitalize() also lowercases the remainder of the string.
const s = "hELLO";
console.log("upperFirst:", _.upperFirst(s));
console.log("capitalize:", _.capitalize(s)); upperFirst: hELLO
capitalize: Hello Example 6 — Sentence-style field labels Format form labels from snake_case keys.
const key = "date of birth";
console.log(_.upperFirst(key)); 🧠 How _.upperFirst() Works 1
Receive string Coerce input to string.
Input
2
First character Uppercase the character at index 0.
Transform
3
Preserve rest Concatenate unchanged remainder.
Output
4
Return New string returned; original unchanged.
Done
Wrap Up
Conclusion _.upperFirst() is the lightest touch for capitalization—one character, no tail rewriting. Reach for _.capitalize() or _.startCase() when you need stricter casing rules.
Pro Tips
💡 Best Practices ✅ Do Use for sentence-style headings and labels Prefer capitalize when tail should be lowercase Handle empty strings in form formatters Combine with trim for user input Import lodash/upperFirst per method ❌ Don’t Expect title case on every word Use when capitalize semantics are required Assume it fixes all-caps input to title case Chain without checking empty input Confuse with startCase Summary
Key Takeaways 📄 01
First char Rest unchanged
Core 📄 02
vs capitalize No tail lower
Compare 📄 03
Headings Sentence style
Use case 📄 04
Empty safe Returns ''
Edge 📄 05
words Next method
Nav ❓ Frequently Asked Questions What does _.upperFirst() do? _.upperFirst() uppercases only the first character of a string and leaves the rest unchanged—for example 'hello' becomes 'Hello'.
How is _.upperFirst() different from _.capitalize()? _.capitalize() uppercases the first character and lowercases the rest. _.upperFirst() only changes the first character.
Does _.upperFirst() title-case every word? No. Only the first character of the entire string changes. For title case per word, use _.startCase() or map over words.
What happens with an empty string? _.upperFirst('') returns ''.
Does _.upperFirst() mutate the input? No. Strings are immutable; a new string is returned.
When should I use _.upperFirst()? For sentence-style labels, formatting user names or headings, and capitalizing the first letter without altering the rest of the casing.
Did you know?
_.upperFirst('hELLO') returns HELLO because only the first character changes—_.capitalize() would return Hello.
Practice _.upperFirst() in the Live Editor Open the Try It editor and run the examples with your own strings.
Open Try It editor → About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion