Strings
Text in quotes.
Text in a program is called a string, because it's a string of characters. Names, messages, and web addresses are all strings. You make one by putting text inside quotes.

- Text is a string
- Names, messages, addresses
- Inside quotes
Joining strings
Plus joins strings together. That's called concatenation. Notice the space inside the quotes, or the words would run together. Length tells you how many characters a string has. And square brackets get a single character, counting from zero. Run it.
const first = "Ada";
const last = "Lovelace";
const full = first + " " + last;
console.log(full);
console.log("length:", full.length);
console.log("first letter:", full[0]);Ada Lovelace length: 12 first letter: A
Quotes inside strings
To put a quote mark inside a string, use the other kind of quote around it. Or put a backslash in front, which is called escaping. Backslash N makes a new line. Strings with plus can get messy, so next we'll learn a much nicer way to build them.
| key | value |
|---|---|
| "It's fine" | single inside double |
| 'Say "hi"' | double inside single |
| \n | new line |
| + | joins strings |
Length and characters
Every string has a length, the number of characters in it, including spaces. You can read a single character with square brackets, counting from zero. So index zero is the first character. And length minus one gives the last one. Run it.
const word = "JavaScript";
console.log(word.length);
console.log(word[0]);
console.log(word[4]);
console.log(word[word.length - 1]);
console.log("Hi there".length);10 J S t 8
Summary
Strings hold text. Plus joins them, length counts characters, and square brackets pick one character. Next, template literals.
Key takeaways- Quotes make strings
- + joins
- str[0] is the first