JSON.stringify · object vs array
Predict the serialized strings and the type of the top-level result.
Code Snippet
const sample = { keep: null, omit: undefined };
console.log(JSON.stringify(sample));
console.log(JSON.stringify([sample.omit, , sample.keep]));
console.log(typeof JSON.stringify(sample.omit));Expected Output & Explanation
{"keep":null}
[null,null,null]
undefined Undefined object property values are omitted, while holes and undefined array entries serialize as null. Stringifying top-level undefined returns actual undefined rather than a JSON string.
Module Context & References
JavaScript · Language output drills Trace closures, receivers, prototypes, coercion and array edge cases
Personal Notes · Markdown