4.
What will be the output of the following code snippet?
const data = '{"name": "John", "age": 30}';
const parsedData = JSON.parse(data);
console.log(parsedData.name);
undefined
30
name
John
Correct: D
The JSON.parse() method is used to parse a JSON string and convert it into a JavaScript object. In this code snippet, the data variable contains a valid JSON string with a key-value pair of "name": "John". After parsing it using JSON.parse(), the parsedData variable will hold a JavaScript object with properties as specified in the JSON string. Therefore, parsedData.name will access the value associated with the name key in the object, which is John. So, the output of console.log(parsedData.name) will be John.