Booleans are primitive data types in JavaScript that can be either true or false.
The JavaScript Boolean object can also be created with the Boolean() constructor.
Boolean bool = new Boolean (value);
console.log(5 === '5'); //false
console.log(6 == '6'); //true
Method | Description | Example |
---|---|---|
toString() | Boolean to string conversion |
|
valueOf() | Provides the boolean primitive value |
|
You may also use the new keyword to construct a boolean value.
const x = true;
// creating a boolean object
const y = new Boolean(false);
console.log(x); // true
console.log(y); // false
console.log(typeof x); // "boolean"
console.log(typeof y); // "object"