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

let trueBool: boolean = true;
let falseBool: boolean = false;

console.log(+trueBool) // 1
console.log(+falseBool) // 0

Output

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…