DEV Community

Discussion on: Daily Challenge #310 - Boolean to String Conversion

Collapse
 
bradtaniguchi profile image
Brad

shortest version I can think of:

javascript

const boolToStr = b => '' + b;
Enter fullscreen mode Exit fullscreen mode

or a more safe version that wont print null or undefined, rather it will convert it to true/false depending on its "truthiness":

javascript

const boolToStr = b => '' + !!b;
Enter fullscreen mode Exit fullscreen mode