Technical skill practice
Check Whether a JavaScript Object Is Empty: Define Which Keys Count
An “empty object” check needs a definition. Object.keys counts own enumerable string keys. Reflect.ownKeys also sees own non-enumerable and symbol keys. Choose the rule that matches the object you are inspecting.
The task
Check an ordinary empty record, then add a hidden property and a symbol. Restrict the helper’s meaning to own properties; it is not a universal emptiness test for Maps, arrays or arbitrary class instances.
Runnable Node 22 example
const assert = require('node:assert/strict');
const record = {};
assert.equal(Object.keys(record).length, 0);
Object.defineProperty(record, 'internal', {value: 7, enumerable: false});
record[Symbol('tag')] = 'memo';
assert.deepEqual(Object.keys(record), []);
assert.equal(Reflect.ownKeys(record).length, 2);
const inherited = Object.create({shared: true});
assert.equal(Object.keys(inherited).length, 0);
assert.equal(Reflect.ownKeys(inherited).length, 0);
console.log(`visible=${Object.keys(record).length}; own=${Reflect.ownKeys(record).length}`);
Expected output and explanation
The visible-key check still reports zero after both additions because neither is an enumerable string key. The all-own-key check reports two. Both observations can be correct under different definitions of empty.
The inherited example has no own keys even though property lookup can find shared. An own-key check answers what belongs directly to that object, not whether lookup can find any value through its prototype. This is why key enumeration should be chosen from the intended contract.
Output from the example
visible=0; own=2
Pitfall to check
Guard against null or undefined before calling an object-enumeration helper. For a Map, size is the relevant entry count; Object.keys(map) would answer a different question. State the supported input shape in a reusable helper.
Questions, answered
Is JSON.stringify(value) === "{}" a good general emptiness test?
It tests a serialization result, which can omit values or invoke custom behavior. Count the intended keys directly instead of defining emptiness through an unrelated conversion.
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.