1

I am getting this error in chrome while mozilla is handling good. I am getting this error to a function which is like this

function abc( xyz = false){ "My logic" }

Error is pointing to '=' operator. please help with this.

Rahul Gupta
  • 972
  • 11
  • 29

2 Answers2

4

That is a standard of ECMASCRIPT version 6 and it's called Default parameters. So it might be not available in your chrome version while FF has.

You can achieve the same by two ways:

function abc( xyz ){ "My logic" }

var pVal = mightbe || false;
abc(pVal); //<---- now pass it here;

or:

function abc( xyz ){ 
    // before processing anything you can do this
    var o = xyz || false; // if there is any value in the xyz then that will
                          // be assigned otherwise false will be the default value.
    "My logic" 
}
Jai
  • 74,255
  • 12
  • 74
  • 103
  • It has nothing to do with destructuring, it's different thing. – dfsq Oct 26 '15 at 07:32
  • Although you're right about being an ES6 standard, the name is Default Parameters. Destructuring assignment is only a subset of it, e.g: `function f([x, y] = [1, 2], {z: z} = {z: 3}) {`. – Buzinas Oct 26 '15 at 07:32
0

This is ES6 syntax, most browsers only support very few ES6 features, you can check from here: https://kangax.github.io/compat-table/es6/ (In your example you used default function parameters)

If you want to write ES6 syntax (which is quite appealing in many ways), you can use some code transpiling tool like babel: https://babeljs.io/

Natural Lam
  • 732
  • 4
  • 13