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


Example:


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


Example


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

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


Related Solutions


Rate this post


Suraj Sharma is the founder of Future Gen AI Services. He holds a B.Tech degree in Computer Science & Engineering from NIT Rourkela.