Summary: 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 firstName: string = 'John';
let title: string = "Web Developer";
Code language: JavaScript (javascript)
TypeScript also supports template strings that use the backtick (`) to surround characters.
The template strings allow you to create multi-line strings and provide string interpolation features.
The following example shows how to create a multi-line string using the backtick (`):
let description = `This TypeScript string can
span multiple
lines
`;
Code language: JavaScript (javascript)
String interpolations allow you to embed the variables into the string like this:
let firstName: string = `John`;
let title: string = `Web Developer`;
let profile: string = `I'm ${firstName}.
I'm a ${title}`;
console.log(profile);
Code language: JavaScript (javascript)
Output:
I'm John.
I'm a Web Developer.
Code language: PHP (php)
Summary
string
type."
), single quotes ('
), and backtick (`) to surround string literals.Was this tutorial helpful ?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4