Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Are all attributes of an object evaluated at the same time in Nodejs?

Let’s take this code:

{ a: Date.now(), b: Date.now() }

It returns: { a: 1664294035466, b: 1664294035466 }

Can I be sure that the keys a and b will always have the same value?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

No, you cannot. Date.now returns the current time at the exact moment it is called. This code will call it twice, and it’s possible (with luck) that the timer ticks over to the next millisecond in between the calls.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading