16. Basic String Properties and Methods
Strings in JavaScript are objects, meaning they come with built-in properties and functions (methods) that allow us to manipulate them.
1. length Property
This is a property (not a method, so no parentheses) that returns the number of characters in the string.
javascript let word = 'Programming'; console.log(word.length); // Output: 11
2. Accessing Characters
Strings are zero-indexed, meaning the first character is at index 0.
javascript let str = 'Code'; console.log(str[0]); // Output: C console.log(str[3]); // Output: e
3. Case Conversion Methods
.toUpperCase().toLowerCase()
javascript let messyName = 'aLiCe JoHnSoN';
console.log(messyName.toUpperCase()); // ALICE JOHNSON console.log(messyName.toLowerCase()); // alice johnson
Note: String methods do not change the original string, they return a new string (because strings are immutable primitives).