Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari - SyntaxError: Cannot declare a let variable twice

This is an error I've never seen before.

Here's a simple repro: https://jsfiddle.net/jakelauer/qr0ysmst/3/

const x = myVar => {

  console.log(myVar);

  for(let myVar of [1,2,3]){
    console.log(myVar);
  }

};

x(10);

Output in Chrome: 10, 1, 2, 3
Output in Safari: SyntaxError: Cannot declare a let variable twice: 'myVar'.

Ideas? Is this a bug in Safari?

Edit - Worth noting, I wouldn't ever do this on purpose. I noticed it because I use the ASP.NET bundling & minification system, and that system did this (so my site broke in Safari)

Edit 2 - Interestingly, this works in both browsers

let x = 10;

for(let x of [1,2,3])
{
    console.log(x);
}

https://jsfiddle.net/jakelauer/aw37pd2s/1/

like image 945
Jake Avatar asked Feb 25 '17 00:02

Jake


1 Answers

Looks like it's a Safari bug. I filed a bug report.

like image 155
Jake Avatar answered Sep 17 '22 22:09

Jake