Evaluation of boolean values in JavaScript

If you have a background in a strongly-typed language such as Java, you’ll be used to using logical operators only with boolean values/expressions. However, in most dynamically-typed languages this doesn’t have to be the case, due to the nature of dynamic typing: The type of the variable is often determined based on the context in which it is used.

With JavaScript there are actually two concepts at play when using logical operators: What is actually returned from the result of a logical operation, and how variables are converted to boolean values when the context requires it.