Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

To handle apostrophe ( single quote, or double quote ) in typescript, use the ( \ ) Escape characters or ( ` ) Template literals it will handle both types quotes single and double.

Let’s see how Escape characters and Template literals will solve the issue.

let brokenString: string = 'I'm a broken string';

console.log(brokenString);

// Output
// unknown: Unexpected token (1:24)

brokenString: string = 'I\'m a broken string';

console.log(brokenString);

// Output
// "I'm a broken string"

brokenString: string = `I'm a "broken" string`;

console.log(brokenString);

// Output
// `I'm a "broken" string`

Today, I’m going to show you How do I handle apostrophe in typescript, as above mentioned, I’m going to use the above-mentioned ( \ ) Escape characters or ( ` ) Template literals.

Let’s start today’s tutorial how do you handle apostrophe in typescript?

TypeScript handle apostrophe example using Escape characters

Here, we will take sample string with quote and will use Escape characters to handle quote in string.

let string: string = 'I\'m a \"broken\" string';

console.log(string);

// Output
// unknown: I'm a "broken" string

Javascript handle apostrophe example using Template literals

Here, we will take sample string with quote and will use Template literals to handle quote in string.

let string: string = `I'm a "broken" string`;

console.log(string);

// Output
// unknown: I'm a "broken" string

I hope it helps you, All the best đź‘Ť.