Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

toUpperCase() is not making the string upper case

Tags:

javascript

I don't know what I'm doing wrong; But somehow .toUpperCase() String-function is not working on my browser or do I get something wrong?

var string ="kjsdgfiIJHBVSFIU";
string.toUpperCase();
console.log(string);

Live demo

like image 908
Don Avatar asked Mar 10 '13 19:03

Don


People also ask

Why is toUpperCase not working?

The "toUpperCase is not a function" error occurs when we call the toUpperCase() method on a value that is not a string. To solve the error, convert the value to a string using the toString() method or make sure to only call the toUpperCase method on strings.

Does toUpperCase change the string?

The toUpperCase() method does not change the value of the original string.

What will be the return type of toUpperCase () method of string?

Return Type: It returns the string in uppercase letters.

How do you put a string in uppercase?

The toUpperCase() method converts a string to upper case letters. Note: The toLowerCase() method converts a string to lower case letters.


2 Answers

.toUpperCase returns the upper-cased string. It is not an in-place modifier method.

string = string.toUpperCase();

Documentation: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/toUpperCase

like image 175
Explosion Pills Avatar answered Sep 30 '22 19:09

Explosion Pills


String is Immutable. Once created, a string object can not be modified.

So here toUpperCase returns a new string, This should work-

var string ="kjsdgfiIJHBVSFIU";
var newString = string.toUpperCase();
alert(newString);
like image 39
ssilas777 Avatar answered Sep 30 '22 19:09

ssilas777