My code (fiddle) is:
let count = 0;
replacer = (k, v) => {
console.log(`count: ${count++}`);
if (v === undefined)
return null;
else
return v;
}
try {
const x = y;
} catch (err) {
console.log(err);
console.log("=====");
console.log(`typeof err is ${typeof err}`);
console.log(JSON.stringify(err));
console.log("-----");
console.log(JSON.stringify(err, replacer));
}
The output is:
ReferenceError: y is not defined
at window.onload ((index):42)
=====
typeof err is object
{}
-----
count: 0
{}
Is err really {}? If not, how do I get a JSON string representation of it?
{"line":42,"column":18,"sourceURL":"https://fiddle.jshell.net/OldGeezer/w2gzkntv/3/show/"}in Safari.{}forconsole.log(err).[[Prototype]], or they might be getters (so are functions and ignored by JSON.stringify). Try for..in.{}, but Safari is showing the expected result, as I said before in my comment. Therefore, this seems to be just a browser implementation difference.JSON.stringify.