Conversions:
Just like for Numbers and "strings", (and also [arrays]booleans can also be converted.
We can convert a boolean into a Number. However, because a boolean has only two values (that is, true or false),
thus a boolean can also have one of only two values, either 0 or 1.
A conversion of a true into a Number will return the number 1.
A conversion of a flase into a Number will return a 0.
Just like an electrical circuit, its either "on" or "off", or here, I/0.
BooleantoNumber:Booleanto"string":
true.toString();
false.toString();
true.toString();
false.toString();
It is also possible to perform Math operations on booleans:
- Unary Operations:
- Binary Operations:
+(or -)true, +(or -)false;
true + true etc;