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.

1
  • 1
    Settings > Languages & Frameworks > JavaScript > select "ECMAScript6" from dropdown. Commented Jan 12, 2017 at 8:44

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

that's it exactly, found an answer for it here too stackoverflow.com/a/37571826/1814446 - if I could I would down vote myself
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.