Javascript Boolean Methods (Examples)

Tech:
Javascript
Since:
1 year ago
Views:
1

In Javascript, boolean is a primitive type. Generally, boolean is used to represent a true or false value. It has two methods, Boolean.valueOf() and Boolean.toString().

toString()

The toString() method returns a string representing the specified object.

var bool = true;
var x = bool.toString();
// true

valueOf()

The valueOf() method returns the primitive value of the specified object.

var bool = true;
var x = bool.valueOf();
// true