HTML1506: Unexpected token in IE
Home » BLOG » WordPress » HTML1506: Unexpected token in IE

HTML1506: Unexpected token in IE

category:  Javascript, jQuery, Web development, WordPress

Yesterday, I received a support task from one of my clients. It was urgent because the users could not buy the product online. The issue occurred only in the IE browser(IE11 and IE edge). I checked the error message at the console and I found “HTML1506: Unexpected token“. I saw the same error back in 2015 when I worked with another client in the USA. This error is very common in IE.

Table of Contents

The cause

The sample of JS code that threw the error is:

function abc(param = '1') {
   // some code...
}

As you can see, the JS function has the default parameter. The default parameter doesn’t work in IE but it works in Firefox and Chrome. IE always behaviors in a strange way.

The solution

To fix the error simply check the param variable inside the function instead of using the default parameter. The code below shows how to fix it.

function abc(param) {
   if( param === undefined ) {
      param = '1';
   }
   // some code... 
}

Yeap. It is an easy and fast solution. I hope it explains well to you. Enjoy the day!