Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Strings 4/5 | Data Types and Variables
Introduction to JavaScript

book
Strings 4/5

Strings are Immutable:

Strings, in JavaScript, are immutable which means that their values cannot be changed once declared.

Let’s try to understand this with an example.

let stringVariable = 'JavaScript';
// changing the value of first character.
stringVariable[0] = 'A';
console.log(stringVariable[0]);
1234
let stringVariable = 'JavaScript'; // changing the value of first character. stringVariable[0] = 'A'; console.log(stringVariable[0]);
copy

The value did not change.

To do so, the usual practice is to create a new string variable with the value that we want to change and attach the parts of the older string to it. In this way, we can change the string,

let str = 'Gi';
// replacing the string G with H
str = 'H' + str[1];
console.log(str);
1234
let str = 'Gi'; // replacing the string G with H str = 'H' + str[1]; console.log(str);
copy
Tarea

Swipe to start coding

A variable name order with the assigned value of go has been given to you. Your task is to change the value go to to and display it.

Solución

let order = 'go';
order = 't' + order[1];
console.log(order)

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 22
let order = 'go';
// your code goes here.

console.log(order)

Pregunte a AI

expand
ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt