Home / Upper and lower case strings with Javascript

Upper and lower case strings with Javascript

I needed to convert a string to lower case the other day with Javascript and wasn’t sure of the exact function name, so turned to my blog but was surprised I didn’t have a post about how to do this… so here it is now.

Lower case a string with Javascript

Yes, it is as obvious as I thought it was, but making a string lower case isn’t something I need to do very often (almost never) which is why I went to look it up. And now that I’ve written a post about it I’ll probably never need to look it up again.

To lower case a string in Javascript

string.toLowerCase()

For example:

alert( "AAA".toLowerCase() );

or

var foo = "AAA";
alert( foo.toLowerCase() );

Both of the above examples will show "aaa" in a alert dialog box.

Upper case a string with Javascript

To upper case a string in Javascript

string.toUpperCase()

For example:

alert( "aaa".toUpperCase() );

or

var foo = "aaa";
alert( foo.toUpperCase() );

Both of the above examples will show "AAA" in a alert dialog box.