I was just messing with some stuff when I stumbled on this. I have the following code:
for(var i = 0; i < 5; i++){
let x = 10;
console.log(x);
x = x + 1;
}
Well, this seems pretty simple: A for loop, which will print the content of x (10) 5 times. But the weird think is, when i ran this on my browser (Chrome, on the last version) the actual result was 5 logs of 10, and 1 log of 11.
Thinking there was a bug on chrome, i tried to run this on repl.it (a website to run code in some programming languages online), the result was the same.
So i tried to run this os some different browsers as well, so after a ran this on Edge and Brave, i still got the same result.
But when i run this on node.js i get the expect result, which is 5 logs of the value 10.
So my question is, why this is happening on all browsers and only node is logging the right result ?
Additional information:
- This seems pretty weird to me, since both chrome and node.js use the same javascript engine (V8).
- I know Brave has the same engine, since it's based on chromium but I tested it anyway, since the same engine is shared between chrome and node, and the result was different.
- The node version i'm currently using is: v12.18.3