Test If a Letter in a String is Uppercase or Lowercase Using JavaScript



To test if a letter in a string is uppercase or lowercase using javascript, you can simply convert the char to its respective case and see the result.

Example

function checkCase(ch) {
   if (!isNaN(ch * 1)){
      return 'ch is numeric';
   }
    else {
      if (ch == ch.toUpperCase()) {
         return 'upper case';
      }
      if (ch == ch.toLowerCase()){
         return 'lower case';
      }
   }
}
console.log(checkCase('a'))
console.log(checkCase('A'))
console.log(checkCase('1'))

Output

This will give the output −

lower case
upper case
ch is numeric
Updated on: 2019-12-02T05:59:26+05:30

7K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements