docs/reference/compat/string/upperFirst.md
::: warning Use upperFirst from es-toolkit
This upperFirst function operates slowly due to conversion logic for handling null or undefined.
Use the faster and more modern upperFirst from es-toolkit instead.
:::
Converts the first character of a string to uppercase.
const upperCased = upperFirst(str);
upperFirst(str)Use upperFirst when you want to capitalize only the first character of a string. The remaining characters stay unchanged.
import { upperFirst } from 'es-toolkit/compat';
// String starting with lowercase
upperFirst('fred');
// Returns: 'Fred'
// String already starting with uppercase
upperFirst('Fred');
// Returns: 'Fred'
// All uppercase string
upperFirst('FRED');
// Returns: 'FRED'
null or undefined is treated as an empty string.
import { upperFirst } from 'es-toolkit/compat';
upperFirst(null); // ''
upperFirst(undefined); // ''
str (string, optional): The string to convert the first character to uppercase.(string): Returns the string with the first character converted to uppercase.