How can I check if a string is all uppercase in JavaScript?

JavascriptFront End TechnologyObject Oriented Programming

You can compare the string against itself in upper case to check if it is in the upper case.

Example

function isUpperCase(str) {
   return str === str.toUpperCase();
}
console.log(isUpperCase('a'))
console.log(isUpperCase('A'))
console.log(isUpperCase('ASDF 123 asd'))
console.log(isUpperCase('TEST 123 TEST'))

Output

This will give the output −

false
true
false
true
raja
Published on 02-Dec-2019 10:30:57
Advertisements