0

I'm sure this has been asked but I'm not sure what to search. Say I have the following code:

const foo = {
  apple: buffer.read(),
  banana: buffer.read(),
  carrot: buffer.read()
};

Is it guaranteed that the apple key will be initialized first, followed by the banana key, and then lastly the carrot key? It matters because the buffer read function internally increments the byte offset for later reading.

If it is not guaranteed I assume I would have to do this instead:

const apple = buffer.read();
const banana = buffer.read();
const carrot = buffer.read();

return { apple, banana, carrot };

But it would be nice if the first one always worked. I'm just not sure if it does.

Ryan Peschel
  • 11,087
  • 19
  • 74
  • 136
  • You can check the spec, but even if it's not stipulated I would be extremely surprised if actual real-world JavaScript environments did not process those top-to-bottom. – Pointy Jan 13 '23 at 00:28

0 Answers0