Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

JavaScript Dictionary

  1. Home
  2. JavaScript Dictionary
  3. String .toUpperCase() / toLowerCase()

String .toUpperCase() / toLowerCase()

Since: ES1(ECMAScript 1997)

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

MethodDescription
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

sample_toUpperCase.js
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 digits and spaces are left as-is.
var mixed = "Hello world 123";
console.log(mixed.toUpperCase()); // Outputs "HELLO WORLD 123".

// Case-insensitive search filtering.
var members = ["Okabe Rintaro", "Makise Kurisu", "Shiina Mayuri", "Hashida Itaru"];
var query = "kurisu";
var i;
for (i = 0; i < members.length; i++) {
	if (members[i].toLowerCase().indexOf(query.toLowerCase()) !== -1) {
		console.log(members[i] + " matched"); // Detects a match regardless of letter case.
	}
}

// URL slug generation: Convert to lowercase and replace spaces with hyphens.
var title = "Future Gadget Lab";
var slug = title.toLowerCase().replaceAll(" ", "-");
console.log(slug); // Outputs "future-gadget-lab".
HELLO WORLD
hello world
Hello World
true
HELLO WORLD 123
Makise Kurisu matched
future-gadget-lab

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

Chrome Chrome
49+
Firefox Firefox
57+
Safari Safari
18+
Edge Edge
80+
11 or earlier ×
IE IE
11+
2 or earlier ×
Opera Opera
48+
2 or earlier ×
iOS Safari iOS Safari
18+
Android Browser Android Browser
37+
4 or earlier ×
Chrome Android Chrome Android
36+
17 or earlier ×
Firefox Android Firefox Android
79+
3 or earlier ×

If you find any errors or copyright issues, please .