Automatic type conversion
For many programming languages, using a function on a value of the incorrect data typeA type of data, such as a number or a string. will result in an error. JavaScript's automatic type conversion feature may instead result in strange behaviour.
Boolean not
(!
) forces the operand to become a Boolean, and hence always returns either true
or false
.
In contrast, the values returned by ||
and &&
may not be Boolean values. These operators both use short-cut evaluationA way of evaluating Boolean expressions joined by and or or so that in some cases not all need to be evaluated before the answer is determined., and in doing so, return the value of the last expression evaluated. This value is expressed as true
or false
if it is a Boolean value and as a non-Boolean value otherwise.
Try to guess the results before clicking on the Run button.
Note:
Hints:
- undefined