You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JavaScript **Boolean** is a data type which can store any one of two values, **true** or **false**.
4
+
E.g. -
5
+
6
+
```
7
+
// Javascript has a specific constructor for creating Boolean type objects
8
+
const testValue = new Boolean(true);
9
+
console.log(testValue); // it prints **Boolean {true}** since testValue is an Object of type Boolean
10
+
```
11
+
12
+
We can directly assign boolean value to any variable, like below:
13
+
14
+
```
15
+
const isTrue = true;
16
+
const isfalse = false;
17
+
```
18
+
19
+
In JavaScript, a **truthy** value is a value that translates to true when evaluated in a Boolean context.
20
+
All values are truthy unless they are defined as **falsy**.
21
+
22
+
Javascript treats an empty string (**""**), **0**, **undefined****null** and **NaN** as **falsy**.
23
+
24
+
Not operator or **!** is the operator which is used to **negate** the boolean aspect of a value.
25
+
26
+
For example:
27
+
```
28
+
const val = 12;
29
+
// using ! operator
30
+
console.log( !false ); // prints true
31
+
console.log( !12 ); // prints false, since 12 is truthy value and negation of a truthy value is falsy
32
+
// using !! operator - this returns just the boolean context of any value
33
+
console.log( !!true ); // prints true
34
+
console.log( !!false ); // prints false
35
+
console.log( !!12 ); // prints true, since 12 is truthy value and negation of a truthy value is falsy, and again negation of that false value is truthy
0 commit comments