Search code examples
javascriptjquerygoogle-chromeconsolepnotify

Uncaught SyntaxError: Unexpected token = in Google Chrome


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.


Solution

  • 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'
        });
    }