A string is a sequence of characters used to store text. It can include letters, numbers, and symbols.
Click to reveal answer
intermediate
How are strings stored in memory?
Strings are stored as a sequence of characters in contiguous memory locations, each character usually taking one or more bytes depending on encoding.
Click to reveal answer
intermediate
What does it mean that strings are immutable in JavaScript?
It means once a string is created, it cannot be changed. Any operation that modifies a string creates a new string instead.
Click to reveal answer
intermediate
Explain the difference between string length and memory size.
String length is the number of characters in the string. Memory size is how many bytes those characters take in memory, which can be more due to encoding.
Click to reveal answer
advanced
What is UTF-16 encoding in JavaScript strings?
UTF-16 is the encoding JavaScript uses to store strings, where most characters use 2 bytes, but some special characters use 4 bytes (surrogate pairs).
Click to reveal answer
Which of the following best describes a string?
AA collection of boolean values
BA single number
CA sequence of characters
DA type of function
✗ Incorrect
A string is a sequence of characters used to represent text.
In JavaScript, what happens when you change a string?
AThe string becomes a number
BThe original string is modified in place
CThe string is deleted
DA new string is created with the change
✗ Incorrect
Strings are immutable in JavaScript, so changes create a new string.
What does string length represent?
ANumber of characters in the string
BNumber of lines in the string
CNumber of words in the string
DNumber of bytes used in memory
✗ Incorrect
String length counts how many characters are in the string.
Which encoding does JavaScript use for strings?
AASCII
BUTF-16
CUTF-8
DISO-8859-1
✗ Incorrect
JavaScript uses UTF-16 encoding for strings.
How are characters stored in memory for strings?
AIn contiguous memory locations
BRandomly scattered
CIn a linked list
DIn a hash table
✗ Incorrect
Characters in strings are stored in contiguous memory locations.
Describe how strings are stored and represented in memory.
Think about how each character is saved one after another and how encoding affects size.
You got /4 concepts.
Explain what it means that strings are immutable in JavaScript and why it matters.
Consider what happens when you try to change a string's content.
You got /4 concepts.
Practice
(1/5)
1. What does the term immutable mean when talking about strings in JavaScript?
easy
A. Strings cannot be changed after they are created
B. Strings can be changed anytime
C. Strings are stored as numbers
D. Strings are always empty
Solution
Step 1: Understand string immutability
In JavaScript, once a string is created, its content cannot be changed directly.
Step 2: Compare options with definition
Strings cannot be changed after they are created - this matches the definition.
Final Answer:
Strings cannot be changed after they are created -> Option A
Quick Check:
Immutable means unchangeable = D [OK]
Hint: Remember: strings can't be changed once made [OK]
Common Mistakes:
Thinking strings can be changed like arrays
Confusing immutability with emptiness
Assuming strings are stored as numbers
2. Which of the following is the correct way to create a string in JavaScript?
easy
A. const str = Hello World;
B. const str = (Hello World);
C. const str = `Hello World;
D. const str = 'Hello World';
Solution
Step 1: Check string syntax rules
Strings must be enclosed in quotes: single (' '), double (" "), or backticks (` `).