JavaScript · Chapter 16 of 55
JavaScript Strings
A string represents text, written inside single quotes, double quotes, or backticks. Strings are immutable — string methods always return a new string.
You can access individual characters by index, and combine strings using the `+` operator or template literals.
Quotes and escaping
Use `\` to escape special characters like quotes inside a string, e.g. `'It\'s here'`. Backticks allow embedded expressions (template literals).
Length and indexing
`str.length` gives the character count. `str[0]` gets the first character; strings are zero-indexed.
Example 1 (javascript)
let s = "Hello";
console.log(s.length);
console.log(s[0]);Output
5
Hlength and bracket indexing on a string.
Example 2 (javascript)
let full = "Java" + "Script";
console.log(full);Output
JavaScriptThe + operator concatenates strings.
Key points
- Strings can use single, double quotes, or backticks.
- Strings are immutable.
- `.length` gives character count; indices start at 0.
- `+` concatenates strings together.
💡 Note: Prefer template literals (backticks) over + concatenation for readability.
