11.) What will JSON.stringify({ key: undefined }) return?
A) {“key”: “undefined”}
B) {“key”: null}
C) Throws an error
D) {}
12.) How do you check if a string is valid JSON in JavaScript?
A) Use JSON.isValid()
B) Parse it with JSON.parse() inside a try…catch block
C) Use typeof to check its type
D) Use JSON.check()
13.) What happens when you pass a replacer function to JSON.stringify()?
A) It filters the properties to be included in the JSON string
B) It ensures all properties are stringified
C) It validates the JSON string
D) Throws an error if the function is invalid
14.) Which of the following is NOT a valid use case of JSON.stringify()?
A) Serializing objects for storage or transmission
B) Converting JavaScript objects into readable JSON format
C) Serializing objects with circular references
D) Formatting JSON output with indentation
15.) What will JSON.stringify(true) return?
A) “true”
B) true
C) “True”
D) Throws an error
16.) How do you deep clone a JSON-compatible object in JavaScript?
A) Use JSON.stringify() and JSON.parse()
B) Use the clone() method
C) Use Object.assign()
D) Use JSON.clone()
17.) How do you check if a given JavaScript object is a valid JSON object?
A) Use typeof to check if it is an object
B) Convert it to a string using JSON.stringify() and back using JSON.parse()
C) Use Array.isArray()
D) Use Object.prototype.toString()
18.) What is the purpose of the space parameter in JSON.stringify()?
A) To add extra spacing between keys and values
B) To format the output with indentation
C) To add a specific number of spaces to the start of the output
D) To compress the JSON output
19.) What happens if you call JSON.stringify() on a Date object?
A) The date is converted to a string in ISO format
B) The date is ignored
C) The date is serialized as a timestamp
D) Throws an error
20.) Which method can be used to transform a JSON object into an iterable array?
A) Object.entries()
B) Object.keys()
C) Object.values()
D) All of the above
Related