Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Safari – SyntaxError: Cannot declare a let variable twice without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
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/
Answer
Looks like it’s a Safari bug. I filed a bug report.
We are here to answer your question about Safari – SyntaxError: Cannot declare a let variable twice - If you find the proper solution, please don't forgot to share this with your team members.