docs/reference/compat/string/toUpper.md
::: warning Use JavaScript's String.prototype.toUpperCase
This toUpper function performs slower due to handling non-string values.
Instead, use the faster and more modern JavaScript's String.prototype.toUpperCase.
:::
Converts a value to a string and then to uppercase.
const uppercased = toUpper(value);
toUpper(value?)Use toUpper when you want to convert a value to an uppercase string. It first converts any type of value to a string, then converts it to uppercase.
import { toUpper } from 'es-toolkit/compat';
// Convert string to uppercase
toUpper('--foo-bar--');
// Returns: '--FOO-BAR--'
toUpper('Hello World');
// Returns: 'HELLO WORLD'
// Convert number
toUpper(123);
// Returns: '123'
// Convert array
toUpper([1, 2, 3]);
// Returns: '1,2,3'
null and undefined are treated as empty strings.
import { toUpper } from 'es-toolkit/compat';
toUpper(null);
// Returns: ''
toUpper(undefined);
// Returns: ''
toUpper();
// Returns: ''
value (unknown, optional): The value to convert to uppercase.(string): Returns the uppercase string.