A string is a sequence of characters enclosed in:
✔ Double quotes → "Hello, World!"
✔ Single quotes → 'JavaScript is fun!'
✔ Backticks (
) for Template Literals → I am learning JavaScript!
Strings are immutable, meaning once created, they cannot be changed. However, you can manipulate them using various methods.
You can access individual characters using indexing ([]
) or .at()
.
let str = "JavaScript";
console.log(str[0]); // Output: J
console.log(str.at(-1)); // Output: t (last character)
.length
- Get String LengthReturns the number of characters in a string.
let text = "Hello, World!";
console.log(text.length); // Output: 13
.charAt(index)
- Get Character at Index