Chapter 09
JavaScript Strings
A string represents text data such as a student's name, city, email address, or message.
01 • Learn
What is JavaScript Strings?
- Strings can be written using single quotes, double quotes, or template literals.
- Individual string characters can be accessed using indexes.
- JavaScript provides many built-in string methods.
- The length property can be used to find the number of characters.
02 • Syntax
Syntax
let name = 'Rahul';
let city = "Delhi";
let message = `Hello ${name}`;
03 • Example
Example
Try understanding this code before running it.
let firstName = 'Rahul'; let lastName = 'Kumar'; let fullName = firstName + ' ' + lastName; console.log(fullName); console.log(fullName.length); console.log(fullName.toUpperCase());
04 • Remember
Important Points
- String indexes start from 0.
- The length property returns the number of characters.
- Many string methods return a new string rather than changing the original string.
- Template literals are useful for inserting values into text.
05 • Avoid
Common Mistakes
- Forgetting to close string quotes.
- Combining strings and numbers without understanding the result.
- Assuming the first character has index 1.
06 • Practical
Real-World Use
Names, addresses, search keywords, messages, email IDs, and product descriptions are examples of string data.
07 • Practice
Practice Exercise
Practice: Strings
Store your first name and last name in separate variables, create the full name, and print it in uppercase.
Ready to write code?
Open the JavaScript editor and run your code with live output.