Description
The JavaScript Boolean method toString()
returns a boolean value as a string.
The method toString()
is a basic method that is available on most JavaScript objects.
This method is used internally by JavaScript when an object needs to be represented as a string.
Syntax
The method toString()
has the below syntax, where bool
is a boolean value.
bool.toString()
Parameters
The method toString()
doesn't allow any parameters.
Result
The method toString()
returns a string value "true" or "false".
Example 1: Using the Method
The below example shows the basic use of the method.
var bool = true;
var boolString = bool.toString();
document.write(bool); // Prints: true
document.write(typeof bool); // Prints: boolean
// The type of data returned by the toString() method is a string
document.write(boolString); // Prints: true
document.write(typeof boolString); // Prints: string
Output:
true
boolean
true
string
Browser Support
This property is introduced with ES1 (ECMAScript 1) in 1997.
It is supported in all modern browsers, like Google Chrome, Internet Explorer or Edge, Firefox, Apple Safari, Opera, etc.,