• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

1. Strings > 1.3. Changing String Case

Changing String Case

NN 2, IE 3

Problem

You want to convert a string to all upper- or lowercase letters.

Solution

Use the two dedicated String object methods, toLowerCase( ) and toUpperCase( ) , for case changes:

var myString = "New York";
var lcString = myString.toLowerCase( );
var ucString = myString.toUpperCase( );

Both methods return modified copies of the original string, leaving it intact. If you want to replace the value of a variable with a case-converted version of the original string (and thus eliminate the original string), reassign the results of the method to the same variable:

myString = myString.toLowerCase( );

Do not, however, redeclare the variable with a var keyword.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint