-
Type: Bug
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: 0.9.5
-
Component/s: Playgrounds
-
3
https://mongodb.slack.com/archives/CUKTSEB6J/p1673269054642729
In a Plaground, the following piece of code prints out the same date twice - always, if I comment out the second print the first date is printed correctly, can someone explain why as it's not the JS behaviour I expect.
firstdate = new ISODate('2016-01-01') print(firstdate) firstdate.setDate(firstdate.getDate() + Math.floor(Math.random()*100)); print(firstdate)
What happens here is that the JS values that are printed are stored and then sent to the output window as one batch when the script has finished executing, and so mutations at later points in the code affect the output