22 lines
759 B
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Understand String Immutability
---
## Understand String Immutability
2019-01-15 14:52:33 -08:00
## Problem Explanation
Correct the assignment to ```myStr``` so it contains the string value of ```Hello World``` using the approach shown in the example above.
2018-10-12 15:37:13 -04:00
2019-01-15 14:52:33 -08:00
## Hint
Instead of ```Jello World ```, ```myStr``` should be assigned ```Hello World```.
2018-10-12 15:37:13 -04:00
2019-01-15 14:52:33 -08:00
## Spoiler Alert! Solution ahead.
**Solution**
```javascript
// Setup
var myStr = "Jello World";
// Only change code below this line
myStr = "Hello World";
```
## Code Explanation
String literals such as ```"Jello World"``` cannot be changed by the individual letter (hence being *immutable*), so the variable containing the incorrect string must be replaced with the desired string using the assignment operator ```=```