1

I've never really used let in JS yet. But with a few dev in my company we just found out something quite strange. I can't explain it.

When I execute the following code in a browser (tested on Chrome Version 51.0.2704.63 (64-bit))

for (let i = 0; i<10000; i++) {
    console.log(typeof null == 'undefined')
} 

4917 false
5083 true

If I use var instead of let then I get 10000 false, which is what's expected.

I tried to run it several times on several webpages and the result is always the same. It makes me wonder if let is correctly integrated within the browsers, because this doesn't seem trustworthy at all and I wonder what kind of other bugs this can produce.

Any insight? The fact that the result is always the same seems to indicate that there is some logic behind it, but I can't grasp it.

Vadorequest
  • 16,593
  • 24
  • 118
  • 215

0 Answers0