> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# upperFirst es-toolkit

Converts the first character of a string to uppercase.

```typescript
const result = upperFirst(str);
```

## Usage

### `upperFirst(str)`

Use `upperFirst` when you want to capitalize only the first letter of a string while keeping the rest of the letters unchanged. It's useful for capitalizing the beginning of sentences or formatting names.

```typescript
import { upperFirst } from 'es-toolkit/string';

// Capitalize the first letter of a lowercase string
upperFirst('fred');
// Returns: 'Fred'

// Keep the string as is if first letter is already uppercase
upperFirst('Fred');
// Returns: 'Fred'

// Keep the string as is even if all letters are uppercase
upperFirst('FRED');
// Returns: 'FRED'
```

Useful in various situations:

```typescript
// Format user names
const userName = 'john';
const displayName = upperFirst(userName);
console.log(displayName); // 'John'

// Capitalize the first letter of a sentence
const sentence = 'hello world';
const capitalizedSentence = upperFirst(sentence);
console.log(capitalizedSentence); // 'Hello world'

// Process multiple names
const names = ['alice', 'bob', 'charlie'];
const capitalizedNames = names.map(name => upperFirst(name));
console.log(capitalizedNames); // ['Alice', 'Bob', 'Charlie']

// Convert camelCase to PascalCase
const camelCase = 'firstName';
const pascalCase = upperFirst(camelCase);
console.log(pascalCase); // 'FirstName'
```

#### Parameters


strstringrequired

The string to capitalize the first letter of.

#### Returns

Returns a string with the first letter converted to uppercase.

```typescript
string
```


Source: es-toolkit

Re-exported verbatim from [`es-toolkit`](https://es-toolkit.dev/reference/string/upperFirst.html). Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.
