In Java 8 using streams when I chain methods one after the another the execution of operations are performed in pipelined manner.
Example:
List
You kinda get the same output, as in the relative values of the sequence of map1, map2 and forEach values are the same.
The difference in order that you're seeing shows the underlying difference between the machine models of the JVM and the JavaScript runtime engine.
JVMs are threaded. JavaScript is not. That means, that your sequence steps in Java can run immediately after the critical number of map operations have occurred.
In JavaScript, the next step is put at the bottom of the execute stack, and every operation at the top must first be executed before getting to the next items.
As you can see, the methods are functionally equivalent, but have different mechanics.