Boolean.toString()

JavaScript 1.1+, ECMAScript 1.0+, JScript 3.0+ Nav3+, IE 4+ Syntax

							boolean.toString()

Description

The toString() method returns the string representation ("true" or "false") of the primitive Boolean value stored in the Boolean object. The return value associated with this object is listed in Table 6.20.

Table 6.20. Return Value Associated with toString()
Type Description
ReturnsIf true, the string "true" is returned. If false, the string "false" is returned.

Example

In Listing 6.66, the toString() method is used to force a comparison of strings rather than Boolean values. Without the toString() method, the if comparison would find the Boolean value not equal to the string value.

Listing 6.66 Force the Correct Comparison ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.