While working on a project I got a JavaScript error saying Uncaught SyntaxError: Unexpected token = in Google Chrome while Firefox was performing fine. I searched on Google for similar questions but couldn’t get the issue with my code. Still later after finding solution for this Uncaught SyntaxError, I decided to post an article as below.
Uncaught SyntaxError: Unexpected token = in Chrome
The problem was that JavaScript doesn’t allow you to pass default parameter to function. We need to assign the default value internally to function. Check the code below:
1 2 3 4 5 6 7 8 | function updateCount (elem, count = 0) { if(count > 0) { // Some code } else { // Some other code } } |
As I was using default parameter feature and it is supported only by Firefox. So I removed default assignment of argument to ‘count‘ parameter from function and redefine in the following manner to deal with Uncaught SyntaxError: Unexpected token =, error appearing in Google Chrome.
1 2 3 4 5 6 7 8 9 | function updateCount (elem, count) { count = count || 0; if(count > 0) { // Some code } else { // Some other code } } |
Which kicked out the issue from Chrome.