Uncaught SyntaxError: Unexpected token = in Google Chrome

Anshad Vattapoyil picture Anshad Vattapoyil · Oct 31, 2013 · Viewed 12.1k times · Source

I have a javascript function which accept an optional parameter. This works fine in Firefox, but in Google Chrome it shows:-

Uncaught SyntaxError: Unexpected token =

My Code,

function errorNotification(text = "Something went wrong!") {
  $.pnotify({
      title: 'Error',
      text: text,
      type: 'error'
  });
}

I have seen lot of similar questions but I can't realize my problem.

Answer

Arun P Johny picture Arun P Johny · Oct 31, 2013

You are using a default parameter feature which is supported only by Firefox now.

function errorNotification(text) {
    text = text || "Something went wrong!";
    $.pnotify({
        title: 'Error',
        text: text,
        type: 'error'
    });
}