3 ms·
No, this is totally different. In the second version, if someObj changes after it was logged, when you'll expand it you'll see the updated value. JSON.stringify
by simlevesque 6y ago
No, this is totally different. In the second version, if someObj changes after it was logged, when you'll expand it you'll see the updated value. JSON.stringify freezes the value. To get the same as the first example, but interactive, you have to do:
console.log("some label: " + JSON.parse(JSON.stringify(someObj)))
- brundolf 6y ago> you have to do Technically you'd have to do console.log("some label: ", JSON.parse(JSON.stringify(someObj))) > In the second version, if someObj changes after it was logged, when you'll expand it you'll see the updated value Yes, this is something to be aware of (and is getting beaten to death throughout this comments section), but if like me you mostly use plain objects in an immutable way, you generally don't have to bother with cloning. Just keep this in the back of your head and know when it won't do what you want in a particular context.
- simlevesque 6y ago> Just keep this in the back of your head I would never debug with that mindstate. I don't trust myself.
- elwell 6y agoIt's only different if you don't treat objects as immutable.