1. let a = [].concat(b);
  2. b = [];

I need to make a copy of array B from array A and clean array B.

Is it guaranteed that after line 1 line 2 will be immediately executed?

And then suddenly the execution will go to the code section, where data will be added to array B and then it will be cleared, but array A will not have this element.

  • one
    if a regular array is used, then yes - Grundy
  • 2
    Offtop, a = b.slice() - faster and does not create an extra empty array. - Alexey Ten

1 answer 1

When using regular arrays, it is impossible to change the value between two consecutive lines. Since the execution takes place in the main thread.

Therefore, if there are no other lines in the example code between line 1 and line 2, they will be executed strictly sequentially.