Boolean is a primitive data type in JavaScript that can store only two values: true and false. Boolean values are mainly used for making decisions in programs such as if statements, loops, and comparisons.
JavaScript provides two boolean values:
Boolean values control program execution.
Since YES is true, the code executes.
Comparison operations return boolean values.
Comparison results are always true or false.
JavaScript provides the Boolean() function to convert values into true or false.
Any non-empty string, non-zero number, array, or object becomes true.
The following values convert to false:
Using the new keyword creates a Boolean object.
The output will be true.
A Boolean object always evaluates to true inside a condition.
Even though the value is false, the object itself is treated as true.
Lowercase boolean is a primitive type. Uppercase Boolean is an object.
JavaScript Boolean values provide the following methods.
| Method | Description |
|---|---|
| toLocaleString() | Returns the Boolean value as a local string. |
| toString() | Converts a Boolean value into a string. |
| valueOf() | Returns the primitive Boolean value. |
| Value | Boolean Result |
|---|---|
| true | true |
| false | false |
| 0 | false |
| "" | false |
| "Hello" | true |
| 100 | true |
Which of the following values returns false using Boolean()?