Description
The JavaScript Boolean method valueOf()
returns the primitive value of a boolean.
The method valueOf()
is usually called by JavaScript behind the scenes, and not explicitly in code.
Syntax
The method valueOf()
has the below syntax, where bool
is a boolean value.
bool.valueOf()
Parameters
The method valueOf()
doesn't accept any parameters.
Result
The method valueOf()
returns the primitive value of a boolean.
Example 1: Using the Method
The below example shows the basic use of the method.
var bool = true;
var boolValue = bool.valueOf();
document.write(bool); // Prints: true
document.write(typeof bool); // Prints: boolean
// The type of data returned by valueOf() method is also a boolean
document.write(boolValue); // Prints: true
document.write(typeof boolValue); // Prints: boolean
Output:
true
boolean
true
boolean
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.,