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
Output
The
!! double exclamation
return false for0
only else it returntrue
for any number.
Thanks for reading…