let b1 = false, b2 = true; alert(b1); alert(b2);
let n1 = 10, n2 = 20, n3 = 10; let n1IsBiggerThanN2 = (n1 > n2); alert(n1IsBiggerThanN2); let n1IsSameAsN3 = (n1 == n3); alert(n1IsSameAsN3);
That is also why you can use a condition in an if statement - it checks the condition and if it evaluates to true, the following code can be reached:
let n1 = 10, n2 = 20; if(n2 > n1) alert("Go on...");
boolean vs. Boolean
Usually, the object version offers you help in dealing with the underlying simple type, while allowing you to even extend this functionality. However, since boolean is SO basic (remember, it only understands the values true or false), the Boolean object is not used very frequently.
You can initiate a new Boolean object like this:
let b1 = Boolean(true); alert(b1);
Here we create a Boolean object with the initial value "true". If we want false, we can simply change this value, or completely leave it out - an empty value is considered false as well:
let b2 = Boolean(); alert(b2);
As a little curiosity, both of these variables will be true:
let b1 = Boolean("false"); alert(b1); let b2 = Boolean("true"); alert(b2);
Why? Because any non-empty value will be considered true.