Navigate back to the homepage

how to handle apostrophe in typescript?

Infinitbility
TypeScript
August 9th, 2022 · 1 min read

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.

1let brokenString: string = 'I'm a broken string';
2
3console.log(brokenString);
4
5// Output
6// unknown: Unexpected token (1:24)
7
8brokenString: string = 'I\'m a broken string';
9
10console.log(brokenString);
11
12// Output
13// "I'm a broken string"
14
15brokenString: string = `I'm a "broken" string`;
16
17console.log(brokenString);
18
19// Output
20// `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.

1let string: string = 'I\'m a \"broken\" string';
2
3console.log(string);
4
5// Output
6// 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.

1let string: string = `I'm a "broken" string`;
2
3console.log(string);
4
5// Output
6// unknown: I'm a "broken" string

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to check nan in react js?

An example of check or handle nan in react js with the step-by-step guide.

August 8th, 2022 · 1 min read

how to check nan in react native?

An example of check or handle nan in react native with the step-by-step guide.

August 7th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]