I have the following pre-configuration
const preloadedConfig = {
"configA": null, // either true, false or null is allowed
};
and then I have the following initialization on page load
let finalConfig = preloadedConfig.configA || true;
The scenario:
Properties in the preloaded config can be changed to either true, false or null based on the user's preference
I wish to use short-circuit evaluation to determine the user choice on page load. If no choice(null) is supplied by the user, default the choice to true
My issue:
Based on the following extracted from here:
Falsy values are those who coerce to false when used in boolean context, and they are 0, null, undefined, an empty string, NaN and of course false.
The following is evaluated:
true >> evaluted true // ok
null >> evaluted true // ok
false >> evaluted true // the problem area
If the user supplies the config option of false, the final evaluated value will always result in true due to it being a "falsy value".
My desired outcome is a boolean value of false if the value supplied is false.
What should I do to make this work while using short-circuit evaluation and allowing 3 types of input values of null, true or false?