The toUpperCase()
, I would like you to tell me how to use it and give me examples because it is difficult for me to understand its structure.
The toUpperCase()
, I would like you to tell me how to use it and give me examples because it is difficult for me to understand its structure.
String#toUpperCase()
convert string string to uppercase:
var nombre = "einer";
console.log(nombre.toUpperCase());
Data types such as Integer, Boolean, Date, and Float and do not have the toUpperCase()
method, so it will throw you an error when calling the method. For example:
var numero = 888;
console.log(numero.toUpperCase());
It's very simple:
var cadena = "hola";
alert(cadena.toUpperCase())
You only use the method in the variable where you have the text you want to apply.
Source: link
The method toUpperCase () converts from a string all the characters in uppercase. Only applies for String data types.
As an example if you define a string:
var cadena = "Laura en StackOverflow!";
and you apply the method toUpperCase () ,
var resultado = cadena.toUpperCase();
You get the same string as the result but with all the characters in uppercase:
LAURA EN STACKOVERFLOW!.
example:
function convierteMayusculas() {
var cadena = "Laura en StackOverflow!.";
var resultado = cadena.toUpperCase();
document.getElementById("demo").innerHTML = resultado ;
}
<!DOCTYPE html>
<html>
<body>
<h1>Convierte el texto a mayusculas:</h1>
<p>Laura en StackOverflow!.</p>
<button onclick="convierteMayusculas()">Convertir</button>
<p id="demo"></p>
</body>
</html>