All tutorials
Basics

Strings

Text values with rich built-in methods and template literals.

1. Explanation

Strings are sequences of characters. Use single, double or backtick quotes. Backticks enable template literals — multiline strings and ${expression} interpolation. Useful methods: length, toUpperCase, toLowerCase, includes, indexOf, slice, split, replace, trim, repeat.

2. Example

Try it yourself
Console
Click Run to see output.

3. Expected output

output
10
JAVASCRIPT
true
java
["a","b","c"]
I am 22 years old

4. Common mistakes

  • Trying to mutate a string (s[0] = 'A') — strings are immutable
  • Using + for complex concatenation instead of template literals
  • Forgetting that .replace replaces only the first match without /g flag

5. Practice questions

  1. Reverse a string
  2. Count how many times the letter 'a' appears in a sentence
  3. Capitalize the first letter of each word
→ Try more practice problems