1

The relevant part of my code is very succinct and simple this time:

const _ = require('lodash');

...

console.log(cur.advantages);
const charDup = _.cloneDeep(cur);
console.log(charDup.advantages);

When I run this code with the subsequent stuff commented out, it works as expected, but when I run it as part of a larger function, I get different values out of these two console.log() functions. I'm baffled.

It almost seems like there's something asynchronous going on, where the second console.log isn't actually running until more changes are made to charDup. But console.log isn't asynchronous. Even lodash.cloneDeep isn't asynchronous, from what I've been able to find on the web.

McKayB
  • 13
  • 4
  • Can you please provide the commented out code? I suspect this is with the behaviour of the console.log in most browsers. To clarify, console.log shows the start of the object in most browsers at the time of last execution, NOT when console.log was called. – Harley Thomas Feb 04 '21 at 22:53
  • The async behavior of console.log answers my question. If you want, I can make another question so you can try to help me debug the subsequent code. – McKayB Feb 04 '21 at 23:00

0 Answers0