0

I've declared this JS function and PhpStorm is highlighting it as an error, saying that ,or) expected.

function getData(params, toCache=true) { ...

enter image description here

Why is PhpStorm highlighting toCache=true as an error? Is this not the correct way to declare default params in JavaScript? My code is working, so is this just a bug in PhpStorm.

LazyOne
  • 148,457
  • 42
  • 363
  • 369
Holly
  • 6,999
  • 19
  • 82
  • 133
  • 1
    Settings > Languages & Frameworks > JavaScript > select "ECMAScript6" from dropdown. – Mjh Jan 12 '17 at 08:44

2 Answers2

3

This is probably because default parameters are part of ES6 specification and your project environment is set to ES5.

pwolaq
  • 6,123
  • 18
  • 45
  • that's it exactly, found an answer for it here too http://stackoverflow.com/a/37571826/1814446 - if I could I would down vote myself – Holly Jan 12 '17 at 08:45
1

Probably, You set PhpStorm to ES5 where default parameters work differently. Example of default parameters for ES5:

function getData(params, toCache){
   if (typeof(toCache)==='undefined') toCache = true;
}

Your code is written on the ES6 and running, PhpStorm highlights.