JavaScript String toUpperCase()

Total
0
Shares

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
Leave a Reply

Your email address will not be published. Required fields are marked *

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.

You May Also Like
JavaScript Array slice()

JavaScript Array slice()

The slice() method in JavaScript returns a shallow copy of a portion of an array as a new array. The original array remains unchanged. slice() Example slice() Syntax The syntax…
View Post
JavaScript String split()

JavaScript String split()

In this tutorial, we will learn about the JavaScript String split() method with examples. The JavaScript String split() method splits a string into an ordered list of strings and returns…
View Post
JavaScript String startsWith()

JavaScript String startsWith()

In JavaScript, the startsWith() method determines whether the given string begins with a specific sequence of characters. Let’s take a look at syntax and examples of the Javascript string startsWith()…
View Post
JavaScript String slice()

JavaScript String slice()

In this tutorial, we will learn about the JavaScript String slice() method with examples. The JavaScript String slice() method extracts a section of the string and returns it as a…
View Post
JavaScript String endsWith()

JavaScript String endsWith()

In JavaScript, the endsWith() method determines whether the given string ends with a specific sequence of characters. Let’s take a look at syntax and examples of the Javascript string endsWith()…
View Post