How to check if first letter of word is a capital letter with JavaScript?

Sometimes, we want to check if first letter of word is a capital letter with JavaScript.

In this article, we’ll look at how to check if first letter of word is a capital letter with JavaScript.

How to check if first letter of word is a capital letter with JavaScript?

To check if first letter of word is a capital letter with JavaScript, we use a regex.

For instance, we write

const word = "Someword";
console.log(/^[A-Z]/.test(word));

to call /^[A-Z]/.test with word to check if the first letter of word starts with a capital letter.

^ is the symbol for the beginning of the string.

[A-Z] is a pattern that matches upper case letters.

Conclusion

To check if first letter of word is a capital letter with JavaScript, we use a regex.