Question 13
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
console.log(JSON.stringify({ a: undefined, b: () => 1, c: NaN, d: null, e: [undefined, () => 1] }));
- A {"a":undefined,"c":NaN,"d":null,"e":[]}
- B {"c":"NaN","d":null,"e":[null]}
- C {"c":null,"d":null,"e":[null,null]} Correct
- D {"a":null,"b":null,"c":null,"d":null,"e":[null,null]}
Correct Answer: Option C
undefined and function properties are dropped, NaN becomes null, and inside arrays undefined and functions become null so the indexes stay correct.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!