feat(curriculum): Add interactive examples to What Is a String in JavaScript, and What Is String Immutability lesson (#63176)

This commit is contained in:
Clarence Bakosi
2025-10-28 20:59:15 +01:00
committed by GitHub
parent 014d31f924
commit 3841cfb963
@@ -5,7 +5,7 @@ challengeType: 19
dashedName: what-is-a-string
---
# --description--
# --interactive--
In JavaScript, a string is a sequence of characters used to represent text data. Strings are one of the primitive data types in the language, along with numbers, booleans, `null`, and `undefined`.
@@ -13,11 +13,17 @@ To create a string in JavaScript, you can use single quotes (`'`), or double quo
Here is an example of creating two variables that hold string values:
:::interactive_editor
```js
let singleQuotes = 'This is a string';
console.log(singleQuotes);
let doubleQuotes = "This is also a string";
console.log(doubleQuotes);
```
:::
Even though you can use single or double quotes to create strings, it's important to be consistent. If a string begins with a single quote, it must also end with a single quote.
The same applies to double quotes. The following example will throw an error because it starts with a double quote and ends with a single quote:
@@ -30,11 +36,17 @@ Another thing to take into account is that strings are immutable. In programming
Here is an example of assigning a new string to a `developer` variable:
:::interactive_editor
```js
let developer = "Jessica";
console.log(developer);
developer = "Quincy";
console.log(developer);
```
:::
Since strings are immutable, we can't update the first string directly. That is why we are assigning a new string to the `developer` variable.
Strings are an important part of programming, and in future lessons, you will learn advanced techniques for manipulating them and harnessing their full potential to create dynamic and interactive applications.