boolean
JavaScript uses true and false to represent the two truth values of logic.
In JavaScript, for each of the three logical operations (AND, OR and NOT) there is a corresponding operator: &&, || and !. In general, there are rules regarding the order of the operations and, in this case, ! (negation) is applied first, and then && (conjunction) and then || (disjunction).
The order of operations between the operators can be overcome by using an operator with higher precedence: ( ), named the 'Grouping operator' or simply said 'parentheses'.
Converting to a Boolean (Truthy/Falsy Values)
With Boolean(value) you can convert any value to a boolean. There is a fixed set of values, so called falsy values, that convert to false. Most importantly, false, 0, empty string, null, undefined and NaN are falsy.
For all other values, Boolean returns true. These values are called truthy.
Boolean(-1);
// => true
Boolean(0);
// => false
Boolean(' ');
// => true
Boolean('');
// => false
Note that because of the described rules, '0', 'false', [] and {} are truthy in JavaScript.
Backlinks