14. How to convert any value to boolean

The easiest way is to use double negation syntax or Boolean constructor

const str = "string"; const one = 1; const zero = 0; console.info(!!str, !!one, !!zero); //true, true, false console.info(Boolean(str), Boolean(one), Boolean(zero)); //true, true, false
devFlipCards 2024

Do you accept cookies?

Cookies are small amounts of data saved locally on you device, which helps our website - it saves your settings like theme or language. It helps in adjusting ads and in traffic analysis. By using this site, you consent cookies usage.