Navigate back to the homepage

How to convert boolean to number in typescript?

January 31st, 2022 · 1 min read
keep affilitate

Hello Friends 👋,

Welcome To Infinitbility! ❤️

Today, we will know the easiest way to convert boolean to number in typescript.

TypeScript has + unary operator which helps you to convert boolean to the number when we add a unary operator with true it will return 1, and with false it will return 0.

Take an example

1let trueBool: boolean = true;
2let falseBool: boolean = false;
4console.log(+trueBool) // 1
5console.log(+falseBool) // 0


TypeScript, boolean to number, example
TypeScript, convert boolean to number example

The + unary operator return 0 for false and 1 for true.

Thanks for reading…

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 number to boolean in typescript?

TypeScript, convert number to boolean example.

January 31st, 2022 · 1 min read

How to remove keys with null values in javascript?

Javascript, remove keys with null values example.

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