Q. Is this reordering of let-bindings expected during the compilation

The language documentation shows that the following example:

let greeting = "hello!"
let score = 10
let newScore = 10 + score

will be compiled into the following JS code:

var greeting = "hello!";
var score = 10;
var newScore = 20;`

However, the generated JS Output (see here) looks like this:

var newScore = 20;
var greeting = "hello1";
var score = 10;

I am wondering if this reordering is intended. If so, we may need to add some clarification. If not and we cannot keep the original order during the compilation, we could use the simpler example to avoid any confusion.

This works as expected, note the order of effectful operation will be preserved

2 Likes