Technical skill practice
JavaScript Boolean: Truthy Values Are Not Parsed Flags
Boolean(value) tests truthiness. It does not parse the meaning of the text “false.” A nonempty string can be truthy even when a human reads it as a negative answer.
The task
Convert a few values, then parse a configuration field that accepts only actual Booleans or the exact strings true and false. Reject other input instead of guessing.
Runnable Node 22 example
const assert = require('node:assert/strict');
assert.equal(Boolean('false'), true);
assert.equal(Boolean(''), false);
assert.equal(Boolean([]), true);
assert.equal(Boolean(0), false);
function parseFlag(value) {
if (value === true || value === 'true') return true;
if (value === false || value === 'false') return false;
throw new TypeError('expected Boolean or exact flag text');
}
assert.equal(parseFlag('false'), false);
assert.equal(parseFlag(true), true);
assert.throws(() => parseFlag('FALSE'), TypeError);
console.log(`coerced=${Boolean('false')}; parsed=${parseFlag('false')}`);
Expected output and explanation
The two printed results answer different questions. Coercion sees a nonempty string; the parser recognizes an explicitly supported spelling. The array assertion also shows that an empty array is truthy, so truthiness is not a container-size check.
The parser deliberately rejects uppercase and whitespace variants. If your input format permits them, normalize only as specified and test those additional cases. Returning a failure or throwing is preferable to quietly turning an unknown spelling into a false flag.
Output from the example
coerced=true; parsed=false
Pitfall to check
Boolean wrappers created with new Boolean are objects and can be truthy even when they wrap false. Prefer primitive Boolean values for flags. Parsing one value is also not a complete feature-flag system with precedence and authorization rules.
Questions, answered
Does double negation parse false text correctly?
No. !!value performs truthiness conversion too, so !!"false" is true. Use a parser matching the text format you accept.
Sources and examples
ResumizeAI team. Examples are fictional teaching material, not customer results. Replace sample details with your own facts.
Your experience. A complete resume.
Build in Resumize with ATS-friendly templates, guided editing and a live preview. Start free, then upgrade when you need more.
Free account required. Free-plan PDF exports include a watermark.