I have confusion over the functionality of JSON.parse.
I am writing code :
dynamicMsgObj = '"rest, no disc"';
var jsonObj = {};
var isJsonString = function isJsonString(str) {
try {
jsonObj = JSON.parse(str);
} catch (e) {
return false;
}
return true;
}(dynamicMsgObj);
console.log(isJsonString);// returns true
console.log(typeof jsonObj);//returns string
How is this happening?? In this way I can't determine if I am receiving string or object, which is my main objective. Please help