

To get the whole word back, we can do this: const publication = "freeCodeCamp" Running the above code, you are going to get a capital F instead of f. As we can imply from the name, you call it on a string/word, and it is going to return the same thing but as an uppercase.įor instance: const publication = "freeCodeCamp" In JavaScript, we have a method called toUpperCase(), which we can call on strings, or words. Now that we know how to access a letter from a word, let's capitalize it.

By exceeding the word length, I mean trying to do something like publication[25, which throws an error because there are only twelve letters in the word "freeCodeCamp". You can replace "0" with any number, as long as you do not exceed the word length. In the same way, you can access other letters from the word. This means that we can get the letter f from freeCodeCamp by doing publication. For instance, the first letter from the word " freeCodeCamp" is at position 0.

For instance, if we have an array, the first position is 0, not 1.Īlso, we can access each letter from a String in the same way that we access an element from an array. Here is an example: const publication = "freeCodeCamp" After you learn how to do this, we'll proceed to the next level – doing it on every word from a sentence. Capitalize the first letter of a wordįirst of all, let's start with capitalizing the first letter of a single word. Therefore, in this article you are going to see multiple ways of solving the same problem. The beautiful thing about programming is that there is no one universal solution to solve a problem. After that, you are going to capitalize the first letter of all words from a sentence. Uppercase: It capitalizes all the all letters of your text.In this article, you are going to learn how to capitalize the first letter of any word in JavaScript. Lowercase: It changes the text from uppercase to lowercase. The case menu offers four options Sentence case: It capitalizes the first letter of each sentence.
