Lodash _.upperFirst() 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 _.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.

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.

📝 Syntax

javascript
_.upperFirst([string=''])
javascript
import upperFirst from "lodash/upperFirst";

const heading = upperFirst("welcome back");
// -> "Welcome back"

⚡ Quick Reference

TaskCode patternResult
Basic_.upperFirst('hello')Hello
Preserve tail_.upperFirst('hELLO')HELLO
Empty_.upperFirst('')''
vs capitalize_.capitalize()Also lowercases rest
vs startCase_.startCase()Every word
Importimport upperFirst from 'lodash/upperFirst'Per-method
Mutates?
No

Returns new string

Scope
1st char

Rest unchanged

vs capitalize
Different

No tail lower

Related
lowerFirst

Inverse

🧰 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.

Examples Gallery

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

📚 Getting Started

Core patterns for _.upperFirst() with copy-ready code.

Example 1 — Capitalize the first character

Turn hello, world! into Hello, world!.

javascript
const text = "hello, world!";
console.log(_.upperFirst(text));
// -> "Hello, world!"
Try It Yourself

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.

javascript
const mixed = "hELLO, wORLD!";
console.log(_.upperFirst(mixed));
// -> "HELLO, wORLD!"
Try It Yourself

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.

javascript
console.log(_.upperFirst(""));
// -> ""
Try It Yourself

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.

javascript
const cmsTitle = "welcome to our website";
console.log(_.upperFirst(cmsTitle));

Example 5 — Compare with _.capitalize()

capitalize() also lowercases the remainder of the string.

javascript
const s = "hELLO";
console.log("upperFirst:", _.upperFirst(s));
console.log("capitalize:", _.capitalize(s));

Example 6 — Sentence-style field labels

Format form labels from snake_case keys.

javascript
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

📝 Notes

Conclusion

_.upperFirst() is the lightest touch for capitalization—one character, no tail rewriting. Reach for _.capitalize() or _.startCase() when you need stricter casing rules.

💡 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

Key Takeaways

📄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

_.upperFirst() uppercases only the first character of a string and leaves the rest unchanged—for example 'hello' becomes 'Hello'.
_.capitalize() uppercases the first character and lowercases the rest. _.upperFirst() only changes the first character.
No. Only the first character of the entire string changes. For title case per word, use _.startCase() or map over words.
_.upperFirst('') returns ''.
No. Strings are immutable; a new string is returned.
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

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