Since properties order in objects is not guaranteed in JavaScript, how does JSON.stringify() actually behave?
- Is the following always true (same object)?
const o = { a: 1, b: 2 };
console.log(JSON.stringify(o) === JSON.stringify(o));
- Is the following always true (deeply equal objects, same key declaration order)?
console.log(JSON.stringify({ a: 1, b: 2 }) === JSON.stringify({ a: 1, b: 2 }));
- How to make the following be true (deeply equal objects, different key declaration order)?
console.log(JSON.stringify({ a: 1, b: 2 }) === JSON.stringify({ b: 2, a: 1 }));