String.prototype.toLowerCase()

Returns a new string with every character converted to lower case using locale-independent rules.

Signature
toLowerCase()
  • Added in JavaScript ES1

Return value

stringA new string representing the calling string converted to lower case. The original string is unchanged.

Errors

Throws a TypeError if called on null or undefined via call() or apply().

toLowerCase() maps every character to its lower-case form using the Unicode Default Case Conversion algorithm — the same result on every machine, regardless of the user's locale. That determinism is exactly why it is the right tool for machine-facing work.

When to reach for it

Use it to canonicalise values before comparing or keying them: email addresses, header names, file extensions, tags, slugs, and enum-like strings arriving from an API. Because the mapping is locale-independent, a value lower-cased on a Turkish user's laptop matches the same value lower-cased on your server.

What trips people up

Lower-casing is not a reliable equality test across scripts. It does not strip accents, so "café" and "cafe" stay different, and it does not unify the two encodings of an accented letter — run normalize() first if the text may come from different sources. Nor is the length preserved: "İ".toLowerCase() is two code units, a plain i plus a combining dot.

For text a human will read in their own language, prefer toLocaleLowerCase(), which honours Turkish dotless ı and similar rules. For sorting or matching that should ignore case, localeCompare() with sensitivity: "base" is more correct than lower-casing both sides.

Example

Try it yourself
Loading editor…
Press Run to execute the code.

When to use it

  • Canonicalise an email address before using it as a lookup key
  • Match a file extension regardless of how the user typed it
  • De-duplicate user-entered tags that differ only in casing

Frequently asked questions

How do I compare two strings ignoring case in JavaScript?

Lower-case both sides — a.toLowerCase() === b.toLowerCase() — which is correct for ASCII identifiers and API values. For human-language text use a.localeCompare(b, locale, { sensitivity: "accent" }) === 0, since it also handles accents and script-specific rules.

What is the difference between toLowerCase and toLocaleLowerCase?

toLowerCase applies the locale-independent Unicode mapping and returns the same result everywhere, while toLocaleLowerCase applies language-specific rules such as Turkish dotless ı. Use toLowerCase for machine keys and toLocaleLowerCase for text a person reads.

Does toLowerCase change the original string?

No. Strings are immutable in JavaScript, so toLowerCase returns a new string and the variable you called it on still holds the original value unless you reassign it.

More examples

Case folding does not remove accents

Lower-casing preserves the accent, so "café" never equals "cafe". It also does not reconcile the composed and decomposed spellings of é — only normalize() does, which is why the last comparison is the one that returns true.

Example · javascript
console.log("CAFÉ".toLowerCase());
console.log("café".toLowerCase() === "cafe");

// Two encodings of the same accented letter stay different.
const composed = "café";
const decomposed = "café";
console.log(composed.toLowerCase() === decomposed.toLowerCase());
console.log(
  composed.normalize("NFC").toLowerCase() ===
    decomposed.normalize("NFC").toLowerCase(),
);

Length is not guaranteed to stay the same

Capital I with dot above lower-cases to two code units: a plain i followed by U+0307 COMBINING DOT ABOVE. The second line shows the locale split — the default algorithm gives "i" for a capital I, while the Turkish locale gives the dotless "ı".

Example · javascript
const turkishI = "İ"; // LATIN CAPITAL LETTER I WITH DOT ABOVE
const lowered = turkishI.toLowerCase();

console.log(JSON.stringify(lowered), lowered.length);
console.log("I".toLowerCase(), "locale-aware:", "I".toLocaleLowerCase("tr"));

Discussion

  • Be the first to comment on this lesson.