The source code for this blog is available on GitHub.

Blog.

JavaScript String toUpperCase()

Cover Image for JavaScript String toUpperCase()
Srinivas Ramakrishna
Srinivas Ramakrishna
Posted underJavaScript

In this tutorial, we will learn about the JavaScript String toUpperCase() method with examples.

The JavaScript String toUpperCase() method converts the string into uppercase and returns a new string.

toUpperCase() Example

// JavaScript Program to illustrate toUpperCase() function

const text = "welcome to javascript world";

// convert uppercase to lowercase
const upperCaseText = text.toUpperCase();
console.log(upperCaseText)


// Output: WELCOME TO JAVASCRIPT WORLD

toUpperCase() Syntax

The syntax of the JavaScript toUpperCase() method is as follows.

str.toUpperCase()

Here the str is the string or the string variable.

toUpperCase() Parameter

The JavaScript toUpperCase() method does not accept any arguments.

toUpperCase() Return Value

The toUpperCase() method converts the given string into uppercase and returns it as a new string. The original string value remains unaffected.

Note: The toUpperCase() method raises TypeError when called on null or undefined.

Example: JavaScript Convert string from lowercase to uppercase

// JavaScript Program to illustrate toUpperCase() function

const text1 = "hello world";
const text2 = "jAvAscriPT iS fun";

console.log(text1.toUpperCase());
console.log(text2.toUpperCase());

Output

HELLO WORLD
JAVASCRIPT IS FUN

More Stories

Cover Image for [Solved] Error: Cannot find module ‘node:events’

[Solved] Error: Cannot find module ‘node:events’

If you are trying to use the Discord.js to develop any custom application and if you are not using latest version of Node.js you will get an Error: Cannot find…
Cover Image for JavaScript String toLowerCase()

JavaScript String toLowerCase()

In this tutorial, we will learn about the JavaScript String toLowerCase() method with examples. The JavaScript String toLowerCase() method converts the string into lowercase and returns a new string. toLowerCase()…