How to check if letter is uppercase in JavaScript

Published Oct 20 2022

You may have noticed some syntax highlighting throughout Far Out Code's blog posts. A delightful yellow denotes functions such as forEach(), while a menacing green is used for primatives such as Boolean. It's like the dark+ VS Code theme, but with more pink and more hippies

. Determining which color of syntax highlighting to use is done simply by checking whether the word begins with an uppercase character. But how do we check if a string starts with a capital letter in JavaScript?

The solution used here is to utilize the charCodeAt(index) function which returns the Unicode

at the given index. We can then check if the unicode is between 65 and 90, the range of uppercase letters in Unicode.

Try it out in the Code Playground.

far out logo

Code Playground

Loading...

Far out, right?

This was pretty far out... now tell me about Binary Search in JavaScript
Far Out Logo
That was pretty far out... but I want to learn about How to use the React useCallback() hook