In this tutorial, you’ll learn about the TypeScript string data type. Like JavaScript, TypeScript uses double quotes ("
) or single quotes ('
) to surround string literals:
let name: string = 'Selvan';
let title: string = "Front-End Developer";
TypeScript also supports template strings that use the backtick (`) to surround characters.
The template strings allow you to create multi-line strings and provide the string interpolation features.
The following example shows how to create multi-line string using the backtick (`):
let description = `This TypeScript string can
span multiple
lines using
the backtick \`
`;
String interpolations allow you to embed the variables into the string like this:
let name: string = `Selvan`;
let title: string = `Front-End Developer`;
let details: string = `I'm ${name}.
I'm a ${title}.`;
console.log(details);
Output:
I'm Selvan.
I'm a Front-End Developer`.
Conclusion
- In TypeScript, all strings get the
string
type. - Like JavaScript, TypeScript uses double quotes (
"
), single quotes ('
), and backtick (`) to surround string literals.