AI solution for JavaScript Quiz on BFE.dev
43. JSON.stringify()
The code below outputs the following by console.log:
["false",false]
[null,null,null,null]
{"a":null,"b":null,"c":null}
The first console.log statement stringifies an array with two elements: "false" (a string) and false (a boolean). This is printed as ["false", false]
.
The second console.log statement stringifies an array with four elements: NaN, null, Infinity, and undefined. When using JSON.stringify, NaN is converted to null, null and undefined remain unchanged, and Infinity is converted to null. This is printed as [null,null,null,null]
.
The third console.log statement stringifies an object with three properties: a, b, and c. The values of these properties are null, NaN, and undefined, respectively. When using JSON.stringify, NaN is converted to null, null and undefined remain unchanged. This is printed as {"a":null,"b":null,"c":null}
.