How to convert a boolean to a string in JavaScript

Last updated on Sep 30, 2020 by Suraj Sharma

In this tutorial, you will learn two ways to convert a boolean value to a string value in JavaScript

1. Using Boolean.toString() method

The toString() method converts a boolean (true or false) to it's respective string


console.log(true.toString()) // "true"

console.log(false.toString()) // "false"

2.Using String Concatenation

We can concatenate a boolean value and an empty '' string to convert it to a string


console.log(''+true) //  "true"

console.log(typeof (''+false) === 'string')  // true

Related Solutions

Rate this post

Suraj Sharma is a Full Stack Software Engineer. He holds a B.Tech degree in Computer Science & Engineering from NIT Rourkela.