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
  • 158,824
  • 45
  • 388
  • 391
Holly
  • 7,462
  • 23
  • 86
  • 140
  • 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,343
  • 19
  • 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.