Here’s a short and straightforward explanation for the string type in TypeScript:
String in TypeScript
The string type is used to represent text values.
Example:
let color: string = "blue";
color = "red";Key Points:
- String values can be enclosed in single quotes (
'), double quotes ("), or backticks (`). - Reassignable: You can change a string value after assignment.
- String Methods: TypeScript supports methods like
.toUpperCase(),.length, etc.
Example with Methods:
let greeting: string = "Hello";
let upperGreeting: string = greeting.toUpperCase(); // "HELLO"
let greetingLength: number = greeting.length; // 5