Search⌘ K

The Multiple Methods of Declaring a String

Explore the different ways to declare strings in TypeScript, including single and double quotes, string interpolation with backticks, and multiline strings. Understand how to embed variables and expressions within strings and write cleaner, more readable code.

Strings on a single line

The first primitive is the string. A string is made of characters. It can be assigned a single quote or a double quote. A string’s content can be a number but will behave as characters if between quotes. Both single and double quotes are accepted. However, the guideline of the TypeScript project uses a double quote. By the way, TypeScript is written in TypeScript! It means the language itself is written with the language, hence following its guidance is a good idea.

TypeScript 3.3.4
let w = "Value1";
let x = "this is a string with the value " + w;
let y = 'this is a string with the value ' + w;
let z = `this is a string ${w}`;
console.log(w,x,y,z)

There is also the ...