There won't be any errors with JSON.stringify in this case.
The error will occur as soon as you attempt to create the object.
var obj = {
name: "Arun" // don't forget the comma
age //this is valid, assuming `age` is defined as a variable earlier in the code for newer browsers
};
In all browsers, there will be a SyntaxError once this part of the script runs due to the missing comma.
If you include the comma and have age
declared above:
var age = 32;
var obj = {
name: "Arun",
age
};
This will work in modern browsers but result in a SyntaxError in older ones.
To make the object compatible with legacy browsers:
var age = 32;
var obj = {
name: "Arun",
age: age
};
Your issue isn't related to .stringify
causing problems.
Based on the provided object, your code is flawed.