A boolean value is one that can either be TRUE or FALSE. If you need to know “yes” or “no” about something, then you would want to use the boolean function. Anything that needs to be “on” or “off”, “yes” or “no”, “true” or “false”, or which just has a temporary purpose, is usually a good fit for booleans.
here is an example of how to use booleans in JavaScript:
var kitchenLights = false;
kitchenLights = true;
kitchenLights;
// Output
true
In this example, the variable “kitchenLights” being set to “true” would indicate that the lights are on. If it was set to “false” then that would mean they are off.
It’s useful to store booleans in variables to keep track of their values and change them over time. Booleans are used as functions to get the values of variables, objects, conditions, and expressions. In fact, Booleans are critical for conditionals to work.
In your code, when you need to know whether or not a condition is being met before proceeding to the next step, the boolean function becomes your best friend. If such and such is TRUE, then do this. If it is FALSE, then do something else.