Hello Friends 👋,

Welcome To Infinitbility! ❤️

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

TypeScript have !! double exclamation which help you to convert number to boolean like when we add double exclamation with 1 it will return true, with 0 it will return false.

Take an example

let statusZero: number = 0;
let statusOne: number = 1;

console.log(!!statusZero) // false
console.log(!!statusOne) // true


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

The !! double exclamation return false for 0 only else it return true for any number.

Thanks for reading…