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
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.
The toUpperCase() method does not change the value of the original string.
Return Type: It returns the string in uppercase letters.
The toUpperCase() method converts a string to upper case letters. Note: The toLowerCase() method converts a string to lower case letters.
.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
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With