TypeScript String

Summary: In this tutorial, you’ll learn about the TypeScript string data type and how to use single quotes, double quotes, and template literals to represent textual values.

Like JavaScript, TypeScript uses double quotes (") or single quotes (') to surround string literals:

let firstName: string = 'John';
let title: string = "Web Developer";

TypeScript also supports template strings that use the backtick (`) to surround characters. 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
`;

String interpolations allow you to embed 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);

Try it

Output:

I'm John. 
I'm a Web Developer.

Summary #

  • In TypeScript, all strings get the string type.
  • Like JavaScript, TypeScript uses double quotes ("), single quotes ('), and backticks (`) to surround string literals.

Quiz #

Quiz

TypeScript Strings

4 questions

Review the lesson learning objectives

Was this helpful?