Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Strings 4/5 | Data Types and Variables
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Introduction to JavaScript (staging)

bookStrings 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.

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,

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

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.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 22
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain why strings are immutable in JavaScript?

How can I change a specific character in a string if strings are immutable?

Can you show more examples of working with immutable strings?

close

bookStrings 4/5

Swipe to show menu

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.

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,

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

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.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 22
single

single

some-alt