Automatic type conversion
For many programming languages, using a function on a value of the incorrect data type 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 evaluation, 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
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
console.log("Boolean operations");
console.log(345.2 == "345.2");
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX