• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • VBA
  • About
You are here: Home / JavaScript / Check if Character is Uppercase in JavaScript

Check if Character is Uppercase in JavaScript

May 15, 2022 Leave a Comment

We can check if a character is uppercase in JavaScript by checking if the letter is equal to the letter after applying the JavaScript toUpperCase() method. Here is a simple function to do this:

function checkCharUpper(letter){
  return letter == letter.toUpperCase();
};

Here is the function in use with an a couple of examples:

function checkCharUpper(letter){
  return letter == letter.toUpperCase();
};

console.log(checkCharUpper("a"));
console.log(checkCharUpper("A"));

#Output:
False
True

When processing strings in a program, it can be useful to know which letters are uppercase and which characters are lowercase. Using JavaScript, we can easily check if a character is uppercase with the help of the JavaScript toUpperCase() method.

To check if a letter is uppercase, we just need to check if that letter is equal to that letter after applying the toUpperCase() method to it.

Below is our JavaScript function again which will check if a character is uppercase.

function checkCharUpper(letter){
  return letter == letter.toUpperCase()
};

How to Check if a Letter is Lowercase in JavaScript

We can also check if a character is lowercase in JavaScript very easily.

To check if a letter is lowercase in JavaScript, we can adjust our function that we defined above to use the JavaScript toLowerCase() method instead of the toUpperCase() method.

Below is a JavaScript function that will check if a character is lowercase.

function checkCharLower(letter){
  return letter == letter.toLowerCase();
};

And here is the function in use with an a couple of examples:

function checkCharLower(letter){
  return letter == letter.toLowerCase();
};

console.log(checkCharLower("a"));
console.log(checkCharLower("A"));

#Output:
True
False

Hopefully this article has been useful for you to learn how to check if a character is uppercase in JavaScript.

Other Articles You'll Also Like:

  • 1.  JavaScript atan – Find Arctangent and Inverse Tangent of Number
  • 2.  JavaScript Check If Number is a Whole Number
  • 3.  Remove Braces from String Using JavaScript
  • 4.  JavaScript asin – Find Arcsine and Inverse Sine of Number
  • 5.  Grouping By Multiple Properties and Summing Using Javascript
  • 6.  JavaScript indexOf – Get the position of a value within a string
  • 7.  Using JavaScript to Replace a Character at an Index
  • 8.  Using JavaScript to Get a Random Number Between Range of Numbers
  • 9.  Using JavaScript to Scroll to the Top of the Page
  • 10.  How to Change the Id of an Element in JavaScript

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

The Programming Expert is a compilation of hundreds of code snippets to help you find solutions to your problems in Python, JavaScript, PHP, HTML, SAS, and more.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2022 · The Programming Expert · About · Privacy Policy