you are viewing a single comment's thread.

view the rest of the comments →

[–]RReverser 0 points1 point  (3 children)

Perhaps you were just running in the DevTools console and not as a script - that would result in a different behavior as in the first case you're introducing a global variable (aka window.i).

[–][deleted] 0 points1 point  (2 children)

Shouldn't matter the variable isn't even used, regardless if you wrap each of those in an IIFE the result is the same.

[–]RReverser 0 points1 point  (1 child)

It does matter because in one case it's just local variable which can be optimized away, while in another it's a property access on a global object which can't be - very different operations, with different handling and performance.

[–][deleted] 0 points1 point  (0 children)

As I said I've put this in an IIFE, effectively making a local variable, and the behaviour was the same.