Technical skill practice
JavaScript Null Check: Distinguish Null, Undefined and a Value
A null check should reflect what null means in your data. In this example it means the sender explicitly supplied an empty middle name, while an absent or undefined field has not supplied a usable value. Test those states separately.
The task
Classify four small records without substituting a fallback. The function reports state; it does not invent a name or make a required-field decision.
Runnable Node 22 example
const assert = require('node:assert/strict');
function state(record) {
if (!Object.hasOwn(record, 'middle')) return 'absent';
if (record.middle === null) return 'explicitly empty';
if (record.middle === undefined) return 'undefined';
return 'provided';
}
assert.equal(state({}), 'absent');
assert.equal(state({middle: null}), 'explicitly empty');
assert.equal(state({middle: undefined}), 'undefined');
assert.equal(state({middle: ''}), 'provided');
console.log([{}, {middle: null}, {middle: undefined}, {middle: 'Lee'}].map(state).join(' | '));
Expected output and explanation
The own-property check separates absence from an explicitly present undefined field. Strict equality then identifies null without collapsing it into another state. An empty string reaches provided because this function’s stated purpose is state classification, not name validation.
That distinction prevents a common overclaim: a present field is not necessarily a valid value. A later validator could reject empty text, limit accepted types or require another field. Keep those rules visible rather than making the null test silently do everything.
Output from the example
absent | explicitly empty | undefined | provided
Pitfall to check
A loose value == null check groups null and undefined. That can be intentional when both mean the same thing, but it would discard a distinction this contract requires. Use ?? for a separate fallback task only after deciding which states may be replaced.
Questions, answered
Does typeof value === "object" rule out null?
No. typeof null is object. An explicit null comparison is needed when the distinction matters.
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.