Navigate back to the homepage

How to convert string to boolean in typescript?

April 13th, 2022 · 1 min read
keep affilitate

Hi Friends 👋,

Welcome to Infinitbility ❤️!

Today, we are going to see how we can convert string to boolean in typescript, here we are going to use the ternary operator to convert string to boolean.

To convert a string to a boolean, we have to check whether 'true' is present in the string or not, and if present we have to assign a new true value or false.

In the following code, we are taken of both cases if the string true or if string false.

1let isActiveStr: string = 'false';
3let isActive: boolean = isActiveStr == 'true' ? true : false;
6let statusStr: string = 'true';
8let status: boolean = statusStr == 'true' ? true : false;

when we run the above code, we get converted value in console check below output.


TypeScript, convert string to boolean example
TypeScript, convert string to boolean example

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.

melio affilitate

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



More articles from Infinitbility

How to convert a string to camel case in typescript?

TypeScript, convert string case to camel case example.

April 11th, 2022 · 1 min read

How to convert object keys to array in typescript?

TypeScript, convert object keys to array example.

April 9th, 2022 · 1 min read
© 2020–2022 Infinitbility
Link to $ to $ to $ to $ to $ to $mailto:[email protected]