• 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
  • Ruby
  • 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.  Using JavaScript to Replace a Space with an Underscore
  • 2.  JavaScript atan – Find Arctangent and Inverse Tangent of Number
  • 3.  Remove Multiple Characters From String in JavaScript
  • 4.  How to Select All Checkboxes in JavaScript
  • 5.  How to Return Multiple Values in JavaScript
  • 6.  JavaScript String startsWith Method
  • 7.  Using JavaScript to Resize an Image
  • 8.  Using JavaScript to Reverse an Array
  • 9.  Remove Special Characters From String in JavaScript
  • 10.  JavaScript acos – Find Arccosine and Inverse Cosine of Number

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

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

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 © 2023 · The Programming Expert · About · Privacy Policy