JavaScript Strings

Master text manipulation and string handling in JavaScript

1
2
3
String Basics & Quote Types

📝 What Are Strings?

Strings are sequences of characters used to represent text in JavaScript. They're fundamental for displaying messages, handling user input, and working with textual data.

const message = "This is a string"

🔤 Three Ways to Create Strings

Single Quotes'text'

Most common for simple strings

'Hello World!'
Double Quotes"text"

Interchangeable with single quotes

"JavaScript Strings"
Template Literals`text`

Backticks for special features

`Template Literals`

⚠️ Quote Matching Rule

The opening and closing quotes must match! Mixing quote types will cause errors.

✅ Good
'Hello World!'
❌ Error
'Hello World!"
String Creation Lab
'Hello World!'
"JavaScript Strings"
`Template Literals`
🚀 Template Literal Magic
Variable Embedding
`Hello, ${name}!` → "Hello, Alice!"
Expression Evaluation
`${10} + ${5} = ${10 + 5}` →
"10 + 5 = 15"
Current Date
`Today is ${new Date().toLocaleDateString()}` →
"Today is 9/5/2025"
📝 Multiline String Editor
Template Literal
`Line 1
Line 2
Line 3`
Escaped String
"Line 1\nLine 2\nLine 3"
🔄 Type Conversion Lab
Conversion Results
Number("123"):0
String(456):""
"123" + 456:"123456"
Pro Tips
💡Use template literals for complex string building with ${}
🎯Template literals preserve line breaks - no need for \n
Escape quotes with backslash: \' or \"
🔢Always use Number() before math operations on user input