String .toUpperCase() / toLowerCase()
Converts all alphabetic characters in a string to uppercase or lowercase. The original string is not modified.
Syntax
// Converts all alphabetic characters to uppercase. string.toUpperCase() // Converts all alphabetic characters to lowercase. string.toLowerCase()
Methods
| Method | Description |
|---|---|
| toUpperCase() | Returns a new string with all alphabetic characters converted to uppercase. |
| toLowerCase() | Returns a new string with all alphabetic characters converted to lowercase. |
Sample Code
var str = "Hello World"; // Converts to uppercase. console.log(str.toUpperCase()); // Outputs "HELLO WORLD". // Converts to lowercase. console.log(str.toLowerCase()); // Outputs "hello world". // The original string is not modified. console.log(str); // Outputs "Hello World" unchanged. // Useful for case-insensitive comparisons. var input = "JavaScript"; var target = "javascript"; console.log(input.toLowerCase() === target.toLowerCase()); // Outputs "true". // Non-alphabetic characters such as Japanese and spaces are left as-is. var mixed = "Hello こんにちは 123"; console.log(mixed.toUpperCase()); // Outputs "HELLO こんにちは 123".
Overview
string.toUpperCase() and string.toLowerCase() are methods that convert the alphabetic characters in a string to uppercase or lowercase. Non-alphabetic characters such as Japanese, digits, and symbols are unaffected and remain unchanged.
The most common use case is case-insensitive string comparison. When searching or matching user input, convert both strings to lowercase before comparing. Because string.indexOf() and string.startsWith() are case-sensitive, these methods are often used together with toLowerCase().
Both methods leave the original string unchanged and return a new string. To use the result, assign it to a variable or use it directly.
Browser Compatibility
2 or earlier ×
2 or earlier ×
Android Browser
37+ ○
4 or earlier ×
Chrome Android
36+ ○
17 or earlier ×
Firefox Android
79+ ○
3 or earlier ×If you find any errors or copyright issues, please contact us.