All Articles

Strings in TypeScript

You can use single quotes '', double quotes "", and backticks/backquotes `` to surround string data in TypeScript.

Templates literals/strings (surrounded by backticks) support embedded expressions with ${expression}.

let userName = 'Bob';

// Logs "My name is Bob"
console.log(`My name is ${userName}`);

let a = 15;
let b = 10;

// Logs "I'm 25"
console.log(`I'm ${a + b}`);

// Logs "I love TypeScript".
console.log(`I ${a > b ? 'love' : 'enjoy'} TypeScript `);

I prefer to use single quotes in most cases. Also, I use string literals for all other cases.