You aren't going to get an error from JSON.stringify, here.
As soon as you try to make this object, you should get an error.
var obj = {
name: "Arun" // you're missing a comma
age //this is valid, as long as `age` exists as a variable above this point, in new browsers
};
In all browsers, as soon as you run this part of the script, it's going to throw a SyntaxError, because you're missing the comma.
If you added that comma back in, and age
did exist above:
var age = 32;
var obj = {
name: "Arun",
age
};
This would now work fine in brand-new browsers, but would again throw a SyntaxError in older browsers.
The legacy-compatible version of that object would look like:
var age = 32;
var obj = {
name: "Arun",
age: age
};
The problem you're having doesn't seem to be that .stringify
would be breaking.
Based on the object you provided, your statement is broken, period.