JavaScript Uppercase Tutorial with Examples – POFTUT

JavaScript Uppercase Tutorial with Examples


JavaScript programming language provides functions in order to change the case of the given string, word or sentence. toUpperCase() is the main function that can be used to make the given string, word and sentence completely uppercase.

toUpperCase() Function Syntax

toUpperCase() function is provided by a JavaScript string object where it can be called with this object directly. toUpperCase() function does not require any parameter as it will use the object value as a parameter to capitalize.

OBJECT.toUpperCase()
  • `OBJECT` is the string value we want to make uppercase. This value can be a letter, word, sentence simply a string data type.
  • `toUpperCase()` is the function we will use to make the OBJECT value uppercase. This function will return the upper

toUpperCase() Examples

toUpperCase() function is related to the string object and can be called from a string variable or string literal like below. In this following example, we will create a string variable named sitename and call the toUpperCase() function and assign the returned value into the sitename_uppercase variable. We will also create a string literal with “poftut.com”  and then call the toUpperCase() function from that string literal which will return the uppercase “POFTUT.COM”.

sitename="poftut.com";
//Prints "poftut.com"
sitename_uppercase=sitename.toUpperCase();
//Prints "POFTUT.COM"
console.log(sitename_uppercase);
//Prints "POFTUT.COM"

console.log(sitename);
//Prints "poftut.com"

"poftut.com".toUpperCase();
//"POFTUT.COM"

a="poftut.com".toUpperCase();
//Prints "POFTUT.COM"
toUpperCase() Examples
toUpperCase() Examples

UpperCase Only First Letter Of The Word

We can also make the first letter of the given word or string uppercase. We will use the charAt() function in order to specify the first letter which index is 0 and then we will use slice() function which will return the remaining string apart from the first letter. In the following example, we will make the string “poftut.com”  first letter uppercase which will look like “Poftut.com”.

sitename="poftut.com";

sitename_uppercase=sitename.charAt(0).toUpperCase()+sitename.slice(1);
//Prints "Poftut.com"

Leave a Comment