Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to 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
Advertisements
