Search code examples
javascriptinternet-explorer-10

semicolon error in javascript for loop in internet explorer 10 and lower version of ie


Hello everyone I have an issue related Internet Explorer 10 and older version,

my code is running properly in all the browser

(Chrome, Firefox, Internet Explorer 11)

but when i tried to run that in Internet Explorer 10 and 9 I am getting the error of

SCRIPT1004: Expected ';'google.map.js (1270,14)

and on that particular line i have a for loop

for (let i = 0; i < Markers.length; i++) {

and my full function

function clearMarker() {
    for (let i = 0; i < Markers.length; i++) {
        Markers[i].setMap(null);
    }
    Markers = new Array();
}

i don't understand why this error is coming in my console. and this is working fine in other browsers,

is it related to compatibility of ie 10 and lesser?


Solution

  • let and const are not valid in IE 10 or below and worse yet they don't work right in IE 11! You shouldn't use them. You should change the let to a var.

    You can find more information at Can I use about what browsers will support it or the MDN article on let